Skip to content

Commit

Permalink
http_server: enable WHERE filtering for GET method
Browse files Browse the repository at this point in the history
  • Loading branch information
sim590 authored and aberaud committed Jun 27, 2017
1 parent b96d0de commit ec6296e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions python/tools/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit ec6296e

Please sign in to comment.