From e7244d3247788b0c8f2b2fc81cc80df17ef3f942 Mon Sep 17 00:00:00 2001 From: matan Date: Mon, 9 Sep 2024 18:20:50 +0300 Subject: [PATCH] allow cors final final (2) --- nodes/http_serving.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nodes/http_serving.py b/nodes/http_serving.py index 02beabe..3157bf3 100644 --- a/nodes/http_serving.py +++ b/nodes/http_serving.py @@ -21,6 +21,15 @@ class HTTPServing: def http_handler(self): class RequestHandler(BaseHTTPRequestHandler): + def do_OPTIONS(self2): + if(self.enable_cross_origin_requests): + self2.send_response(200) + self2.send_header('Access-Control-Allow-Origin', '*') + self2.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') + self2.send_header('Access-Control-Allow-Headers', '*') + self2.end_headers() + + def do_POST(self2): content_length = int(self2.headers['Content-Length']) post_data = self2.rfile.read(content_length) @@ -37,7 +46,7 @@ class HTTPServing: if(self.enable_cross_origin_requests): self2.send_header('Access-Control-Allow-Origin', '*') self2.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS') - self2.send_header('Access-Control-Allow-Headers', 'X-Requested-With') + self2.send_header('Access-Control-Allow-Headers', '*') self2.end_headers() self2.wfile.write(json.dumps(response).encode('utf-8'))