From 462191a08b5b2efb83f5bc32935dc546d35a744b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 12 Oct 2017 22:53:20 -0400 Subject: Implement zlib streaming for the gateway. --- discord/http.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'discord/http.py') 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)) -- cgit v1.2.3