diff --git a/aiohttp/client.py b/aiohttp/client.py index 4f3dad59de8..7f667caf677 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -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: diff --git a/changes/2114.bugfix b/changes/2114.bugfix new file mode 100644 index 00000000000..451299998fd --- /dev/null +++ b/changes/2114.bugfix @@ -0,0 +1 @@ +Support HTTP 308 Permanent redirect in client class. \ No newline at end of file diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 127cabdf686..9b2bc20f925 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -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