File size: 2,119 Bytes
5f18352
aac89d0
9a2171d
5f18352
 
 
c08916d
f18de34
5f18352
 
 
 
1526076
aac89d0
5f18352
 
 
 
a7a2ec5
5f18352
 
 
 
2c62d5a
5f18352
 
 
 
90c18d5
4d2703c
90c18d5
599b375
 
 
 
 
4d2703c
599b375
 
 
 
 
 
 
 
 
 
 
 
 
5f18352
2c62d5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, request, Response
import cloudscraper
scraper = cloudscraper.create_scraper(interpreter='nodejs')

app = Flask(__name__)

@app.route('/proxy/<scheme>:/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def proxy(scheme, url):
    req_method = request.method
    req_headers = {key: value for key, value in request.headers if key != 'Host'}
    req_data = request.get_data()

    resp = scraper.request(method=req_method,
                            url=f'{scheme}://{url}',
                            headers=req_headers,
                            data=req_data,
                            stream=True)

    excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
    headers = [(name, value) for (name, value) in resp.raw.headers.items()
               if name.lower() not in excluded_headers]

    def generate():
        for chunk in resp.iter_content(chunk_size=1):
            yield chunk

    return Response(generate(), status=resp.status_code, headers=headers)

@app.route('/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
@app.route('/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'])
def cf(url=""):
    req_method = request.method
    req_headers = {key: value for key, value in request.headers if key != 'Host'}
    req_data = request.get_data()

    resp = scraper.request(method=req_method,
                            url=f'https://chat-shared3.zhile.io/{url}',
                            headers=req_headers,
                            data=req_data,
                            stream=True)

    excluded_headers = [] #['content-encoding', 'content-length', 'transfer-encoding', 'connection']
    headers = [(name, value) for (name, value) in resp.raw.headers.items()
               if name.lower() not in excluded_headers]

    def generate():
        for chunk in resp.iter_content(chunk_size=1):
            yield chunk

    return Response(generate(), status=resp.status_code, headers=headers)
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)