http server allowing cors

master
Eggert Jung 5 years ago
commit 438cbe0af2

@ -0,0 +1,25 @@
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length)
self.send_response(204)
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
#print(body)
for item in body.decode().split(','):
print(item)
def do_OPTIONS(self):
print(self.headers)
self.send_response(204)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Method', 'POST, GET, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'content-type')
self.end_headers()
httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()
Loading…
Cancel
Save