diff --git a/python/tools/http_server.py b/python/tools/http_server.py index 0498eff3220f0d2e5d1a70f8132bb74647843759..f54495a157d5ba25f6dad2cd02c735ac9cefeb1c 100755 --- a/python/tools/http_server.py +++ b/python/tools/http_server.py @@ -32,10 +32,13 @@ class DhtServer(resource.Resource): self.node.bootstrap(b_url.hostname, str(b_url.port) if b_url.port else '4222') def render_GET(self, req): - uri = req.uri[1:] - h = dht.InfoHash(uri) if len(uri) == 40 else dht.InfoHash.get(uri.decode()) - print('GET', '"'+uri.decode()+'"', h) - res = self.node.get(h) + uri = req.uri[1:].decode().rsplit('?', 1)[0] + h = dht.InfoHash(uri.encode()) if len(uri) == 40 else dht.InfoHash.get(uri) + w = dht.Where('WHERE '+''.join(k.decode()+'='+req.args[k][0].decode()+',' + for k in req.args.keys() + if k in [b'id', b'user_type', b'value_type', b'owner', b'seq'])[:-1]) + print('GET', '"'+uri+'"', h, w) + res = self.node.get(h, where=w) req.setHeader(b"content-type", b"application/json") return json.dumps({'{:x}'.format(v.id):{'base64':base64.b64encode(v.data).decode()} for v in res}).encode()