from flask import Flask, request, Response import requests app = Flask(__name__) @app.route('/proxy/', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']) def proxy(url): req_method = request.method req_headers = {key: value for key, value in request.headers if key != 'Host'} req_data = request.get_data() resp = requests.request(method=req_method, url=f'https://{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=4096): yield chunk return Response(generate(), status=resp.status_code, headers=headers) if __name__ == '__main__': app.run(port=7860)