Skip to content

Commit

Permalink
Support HTTP 308 Permanent redirect in client class. (#2134)
Browse files Browse the repository at this point in the history
Implements: #2114
  • Loading branch information
penguinolog authored and asvetlov committed Jul 27, 2017
1 parent 91dc5b7 commit 07a4ef3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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

0 comments on commit 07a4ef3

Please sign in to comment.