mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
http_server: enable WHERE filtering for GET method
This commit is contained in:
1 parent
b96d0de8a2
commit
ec6296e44b
1 file changed
+7
-4
@@ -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()
|
||||
|
||||
|
||||
Reference in new issue
Block a user