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

Support HTTP 308 Permanent redirect in client class. #2134

Merged
merged 1 commit into from
Jul 27, 2017
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
3 changes: 2 additions & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def _request(self, method, url, *,
self._cookie_jar.update_cookies(resp.cookies, resp.url)

# redirects
if resp.status in (301, 302, 303, 307) and allow_redirects:
if resp.status in (
301, 302, 303, 307, 308) and allow_redirects:
redirects += 1
history.append(resp)
if max_redirects and redirects >= max_redirects:
Expand Down
1 change: 1 addition & 0 deletions changes/2114.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support HTTP 308 Permanent redirect in client class.
24 changes: 24 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,30 @@ def redirect(request):
resp.close()


@asyncio.coroutine
def test_HTTP_308_PERMANENT_REDIRECT_POST(loop, test_client):
@asyncio.coroutine
def handler(request):
return web.Response(text=request.method)

@asyncio.coroutine
def redirect(request):
yield from request.read()
return web.HTTPPermanentRedirect(location='/')

app = web.Application()
app.router.add_post('/', handler)
app.router.add_post('/redirect', redirect)
client = yield from test_client(app)

resp = yield from client.post('/redirect', data={'some': 'data'})
assert 200 == resp.status
assert 1 == len(resp.history)
txt = yield from resp.text()
assert txt == 'POST'
resp.close()


@asyncio.coroutine
def test_HTTP_302_max_redirects(loop, test_client):
@asyncio.coroutine
Expand Down