From 36f6e2f05586aaf9ca501dd60e375d88170dd168 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 2 Aug 2019 00:55:22 +0100 Subject: [PATCH] Switch to requests session persistent headers --- disco/api/http.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/disco/api/http.py b/disco/api/http.py index c699e8f..7ca3dac 100644 --- a/disco/api/http.py +++ b/disco/api/http.py @@ -206,18 +206,18 @@ class HTTPClient(LoggingClass): sys.version_info.micro) self.limiter = RateLimiter() - self.headers = { + self.after_request = after_request + + self.session = requests.Session() + self.session.headers.update({ 'User-Agent': 'DiscordBot (https://github.com/b1naryth1ef/disco {}) Python/{} requests/{}'.format( disco_version, py_version, requests_version), - } + }) if token: - self.headers['Authorization'] = 'Bot ' + token - - self.after_request = after_request - self.session = requests.Session() + self.session.headers['Authorization'] = 'Bot ' + token def __call__(self, route, args=None, **kwargs): return self.call(route, args, **kwargs) @@ -255,12 +255,6 @@ class HTTPClient(LoggingClass): args = args or {} retry = kwargs.pop('retry_number', 0) - # Merge or set headers - if 'headers' in kwargs: - kwargs['headers'].update(self.headers) - else: - kwargs['headers'] = self.headers - # Build the bucket URL args = {k: to_bytes(v) for k, v in six.iteritems(args)} filtered = {k: (v if k in ('guild', 'channel') else '') for k, v in six.iteritems(args)}