-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorsServer.py
More file actions
36 lines (28 loc) · 1.14 KB
/
CorsServer.py
File metadata and controls
36 lines (28 loc) · 1.14 KB
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
#/usr/bin/python
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def do_POST(self):
print "post"
content_length = int(self.headers['Content-length'])
bytes_read = 0
while bytes_read < content_length:
x = self.rfile.read(1)
bytes_read += 1
print "Read POST data"
message = "Upload to geodata.example.net complete"
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "http://portal.example.com:9999")
self.send_header("Content-Length", str(len(message)))
self.send_header("Content-Type", "text/plain");
self.end_headers()
print message
self.wfile.write(message);
def do_OPTIONS(self):
print "options"
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "http://portal.example.com:9999")
self.send_header("Access-Control-Allow-Methods", "POST")
self.end_headers()
if __name__ == "__main__":
BaseHTTPServer.test(CORSRequestHandler, BaseHTTPServer.HTTPServer)