-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_server.py
33 lines (27 loc) · 928 Bytes
/
input_server.py
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
import http.server
import record_training_data
class HttpServerHandler(http.server.BaseHTTPRequestHandler):
"""
A simple HTTP server capable of handling GET and POST requests
"""
def _set_headers(self, response=None, connection=None):
self.send_response(200)
self.send_header('Content-Type', 'text/html; charset=utf-8')
if response is not None:
self.send_header('Content-Length', len(response))
if connection is not None:
self.send_header('Connection', connection)
self.end_headers()
def do_HEAD(self):
self._set_headers()
def do_POST(self):
# print('POST received\n')
self.send_response(200)
self.protocol_version = 'HTTP/1.1'
self.end_headers()
content_length = int(self.headers['Content-Length'])
input = self.rfile.read(content_length).decode('utf-8').replace('payload=', '').split("x")
response = b'ok'
self.wfile.write(response)
def log_message(self, format, *args):
return