From 6fc14d327c749d631b3bc83443934cab2d651af7 Mon Sep 17 00:00:00 2001 From: Raoel Oomen Date: Thu, 3 Sep 2020 13:44:50 +0200 Subject: [PATCH 1/2] we should handle OPTIONS requests too (related to newer python libs?) --- src/webserver.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/webserver.py b/src/webserver.py index 7880b3b..7fa5803 100644 --- a/src/webserver.py +++ b/src/webserver.py @@ -2,10 +2,10 @@ Basic web server / framework. """ -from SocketServer import ThreadingMixIn import BaseHTTPServer -import urlparse import cgi +import urlparse +from SocketServer import ThreadingMixIn class HTTPError(Exception): @@ -57,6 +57,14 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): environ={'REQUEST_METHOD': 'POST'}) self._call(self.path.strip('/'), params={'form_values': form_values}) + def do_OPTIONS(self): + self.send_response(200, "ok") + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') + self.send_header("Access-Control-Allow-Headers", "X-Requested-With") + self.send_header("Access-Control-Allow-Headers", "Content-Type, Authorization") + self.end_headers() + def _parse(self, reqinfo): """ Parse information from a request. From 8706e904341e8a1af6a23f27da0fc10ad73c107a Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Mon, 7 Sep 2020 08:56:53 +0200 Subject: [PATCH 2/2] Fix linting issues --- src/webserver.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/webserver.py b/src/webserver.py index 7fa5803..b322a35 100644 --- a/src/webserver.py +++ b/src/webserver.py @@ -57,12 +57,16 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): environ={'REQUEST_METHOD': 'POST'}) self._call(self.path.strip('/'), params={'form_values': form_values}) - def do_OPTIONS(self): - self.send_response(200, "ok") + def do_OPTIONS(self): # pylint: disable=invalid-name + """ + Handle OPTIONS request and return CORS headers. + """ + self.send_response(200, 'ok') self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS') - self.send_header("Access-Control-Allow-Headers", "X-Requested-With") - self.send_header("Access-Control-Allow-Headers", "Content-Type, Authorization") + self.send_header('Access-Control-Allow-Headers', 'X-Requested-With') + self.send_header('Access-Control-Allow-Headers', 'Content-Type, ' + 'Authorization') self.end_headers() def _parse(self, reqinfo):