Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redirects for HEAD requests. #1147

Merged
merged 1 commit into from
Sep 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def _request(self, method, url, *,

# For 301 and 302, mimic IE behaviour, now changed in RFC.
# Details: https://github.com/kennethreitz/requests/pull/269
if resp.status != 307:
if (resp.status == 303 and resp.method != hdrs.METH_HEAD) \
or (resp.status in (301, 302) and
resp.method == hdrs.METH_POST):
method = hdrs.METH_GET
data = None
if headers.get(hdrs.CONTENT_LENGTH):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,29 @@ def redirect(request):
resp.close()


@asyncio.coroutine
def test_HTTP_302_REDIRECT_HEAD(create_app_and_client):
@asyncio.coroutine
def handler(request):
return web.Response(text=request.method)

@asyncio.coroutine
def redirect(request):
return web.HTTPFound(location='/')

app, client = yield from create_app_and_client()
app.router.add_get('/', handler)
app.router.add_get('/redirect', redirect)
app.router.add_head('/', handler)
app.router.add_head('/redirect', redirect)

resp = yield from client.request('head', '/redirect')
assert 200 == resp.status
assert 1 == len(resp.history)
assert resp.method == 'HEAD'
resp.close()


@asyncio.coroutine
def test_HTTP_302_REDIRECT_NON_HTTP(create_app_and_client):

Expand Down