aboutsummaryrefslogtreecommitdiff
path: root/discord/http.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-10-14 21:17:27 -0400
committerRapptz <[email protected]>2017-10-14 21:19:46 -0400
commit47a58d354d3c289ce8fcd56f817976a43029887f (patch)
tree7ff778c55d34b1155bad246bfec32870db6b726c /discord/http.py
parentShow sha1 for development versions. (diff)
downloaddiscord.py-47a58d354d3c289ce8fcd56f817976a43029887f.tar.xz
discord.py-47a58d354d3c289ce8fcd56f817976a43029887f.zip
Reimplement zlib streaming.
This time with less bugs. It turned out that the crash was due to a synchronisation issue between the pending reads and the actual shard polling mechanism. Essentially the pending reads would be cancelled via a simple bool but there would still be a pass left and thus we would have a single pending read left before or after running the polling mechanism and this would cause a race condition. Now the pending read mechanism is properly waited for before returning control back to the caller.
Diffstat (limited to 'discord/http.py')
-rw-r--r--discord/http.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/discord/http.py b/discord/http.py
index fa6678ee..8c4ebb16 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -739,21 +739,29 @@ class HTTPClient:
return self.request(Route('GET', '/oauth2/applications/@me'))
@asyncio.coroutine
- def get_gateway(self):
+ def get_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = yield from self.request(Route('GET', '/gateway'))
except HTTPException as e:
raise GatewayNotFound() from e
- return data.get('url') + '?encoding=json&v=6'
+ if zlib:
+ value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
+ else:
+ value = '{0}?encoding={1}&v={2}'
+ return value.format(data['url'], encoding, v)
@asyncio.coroutine
- def get_bot_gateway(self):
+ def get_bot_gateway(self, *, encoding='json', v=6, zlib=True):
try:
data = yield from self.request(Route('GET', '/gateway/bot'))
except HTTPException as e:
raise GatewayNotFound() from e
+
+ if zlib:
+ value = '{0}?encoding={1}&v={2}&compress=zlib-stream'
else:
- return data['shards'], data['url'] + '?encoding=json&v=6'
+ value = '{0}?encoding={1}&v={2}'
+ return data['shards'], value.format(data['url'], encoding, v)
def get_user_info(self, user_id):
return self.request(Route('GET', '/users/{user_id}', user_id=user_id))