Skip to content

Commit

Permalink
Merge pull request #132 from andreasots/aiohttp-pls
Browse files Browse the repository at this point in the history
Workaround for #130: Do GET requests instead of HEAD.
  • Loading branch information
andreasots committed Jan 10, 2016
2 parents 16d6b4e + 8afc022 commit 81ad49c
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 81ad49c

Please sign in to comment.