def process_input(self, s, cl, addr):
print('client connected from', addr)
cl.settimeout(None)
if not hasattr(cl, 'readline'):
# CPython
client_stream = cl.makefile("rwb")
else:
# MicroPython
client_stream = cl
req = client_stream.readline()
print(req)
while True:
data = client_stream.readline()
if not data or data == b'\r\n':
break
method, path, protocol = req.split(b' ')
if method.lower() == b'get':
if path == b'/':
self.send(cl, 200, filename='index.html', content_type='text/html; charset=utf-8')
elif path == b'/commands':
commands = ', '.join('"' + c + '"' for c in sorted(WebApp.commands))
self.send(cl, 200, '[' + commands + ']', content_type='application/json')
else:
self.send(cl, 404)
elif method.lower() == b'post':
try:
func = WebApp.commands[path.lstrip(b'/').decode('ascii')]
except KeyError:
self.send(cl, 404)
return
self.send(cl, 200)
return func
else:
self.send(cl, 400)
#mem = gc.mem_alloc()
#gc.collect()
#print("Freeing", mem - gc.mem_alloc(), "now free", gc.mem_free())
评论列表
文章目录