mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
bug5440: added Python web server configuration/httpserver.py that handles POST correctly
This commit is contained in:
1 parent
d81b17521c
commit
ccb6a5677d
1 file changed
+31
@@ -0,0 +1,31 @@
|
||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
||||
import SocketServer
|
||||
import simplejson
|
||||
|
||||
class S(SimpleHTTPRequestHandler):
|
||||
def _set_headers(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
print "got get request %s" % (self.path)
|
||||
if self.path == '/':
|
||||
self.path = '/index.html'
|
||||
return SimpleHTTPRequestHandler.do_GET(self)
|
||||
|
||||
def do_POST(self):
|
||||
print "got post!!"
|
||||
self._set_headers()
|
||||
content_len = int(self.headers.getheader('content-length', 0))
|
||||
post_body = self.rfile.read(content_len)
|
||||
test_data = simplejson.loads(post_body)
|
||||
print "post_body(%s)" % (test_data)
|
||||
self.wfile.write("received POST request:<br>{}".format(post_body))
|
||||
|
||||
def run(handler_class=S, port=50000):
|
||||
httpd = SocketServer.TCPServer(("", port), handler_class)
|
||||
print 'Starting httpd...'
|
||||
httpd.serve_forever()
|
||||
|
||||
run()
|
||||
Reference in new issue
Block a user