From 8afc022109d153fd72dc030ebd46c895d90df048 Mon Sep 17 00:00:00 2001 From: Andreas Ots Date: Sun, 10 Jan 2016 14:58:59 +0200 Subject: [PATCH] Workaround for #130: Do GET requests instead of HEAD. --- common/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/utils.py b/common/utils.py index d457b63b..de70312e 100644 --- a/common/utils.py +++ b/common/utils.py @@ -446,6 +446,12 @@ def http_request(url, data=None, method='GET', maxtries=3, headers={}, timeout=5 def http_request_coro(url, data=None, method='GET', maxtries=3, headers={}, timeout=5, allow_redirects=True): headers["User-Agent"] = "LRRbot/2.0 (https://lrrbot.mrphlip.com/)" firstex = None + + # FIXME(#130): aiohttp fails to decode HEAD requests with Content-Encoding set. Do GET requests instead. + real_method = method + if method == 'HEAD': + real_method = 'GET' + if method == 'GET': params = data data = None @@ -453,7 +459,7 @@ def http_request_coro(url, data=None, method='GET', maxtries=3, headers={}, time params = None while True: try: - res = yield from asyncio.wait_for(http_request_session.request(method, url, params=params, data=data, headers=headers, allow_redirects=allow_redirects), timeout) + res = yield from asyncio.wait_for(http_request_session.request(real_method, url, params=params, data=data, headers=headers, allow_redirects=allow_redirects), timeout) if method == "HEAD": yield from res.release() return res