mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-16 10:48:47 +00:00
32 lines
991 B
Python
32 lines
991 B
Python
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()
|