Skip to content

Commit

Permalink
Workaround for mrphlip#130: Do GET requests instead of HEAD.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasots committed Jan 10, 2016
1 parent 16d6b4e commit 8afc022
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,20 @@ 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
else:
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
Expand Down

0 comments on commit 8afc022

Please sign in to comment.