From ec6296e44b0eadaef116c6ebcbf2de4109666fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20D=C3=A9saulniers?= Date: Thu, 22 Jun 2017 18:38:26 -0400 Subject: [PATCH] http_server: enable WHERE filtering for GET method --- python/tools/http_server.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/tools/http_server.py b/python/tools/http_server.py index 0498eff32..f54495a15 100755 --- a/python/tools/http_server.py +++ b/python/tools/http_server.py @@ -32,10 +32,13 @@ def __init__(self, port, bootstrap): 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()