From 79fa7bf77d1528b387fc7bc1ba906631ddc51b62 Mon Sep 17 00:00:00 2001 From: Nikolay Novik Date: Mon, 28 Aug 2017 20:44:31 -0400 Subject: [PATCH 1/2] add test case --- aiohttp_debugtoolbar/middlewares.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aiohttp_debugtoolbar/middlewares.py b/aiohttp_debugtoolbar/middlewares.py index 924ce00a..14002b53 100644 --- a/aiohttp_debugtoolbar/middlewares.py +++ b/aiohttp_debugtoolbar/middlewares.py @@ -123,7 +123,9 @@ def toolbar_middleware(request): if intercept_redirects: # Intercept http redirect codes and display an html page with a # link to the target. - if response.status in REDIRECT_CODES and response.location: + if response.status in REDIRECT_CODES \ + and getattr(response, 'location', None): + context = {'redirect_to': response.location, 'redirect_code': response.status} From 07d321642ba845a8c60f15fcbdd71023c03fd5e7 Mon Sep 17 00:00:00 2001 From: Nikolay Novik Date: Mon, 28 Aug 2017 20:44:55 -0400 Subject: [PATCH 2/2] add test case --- tests/test_middleware.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_middleware.py b/tests/test_middleware.py index fedca860..4b50d151 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -65,6 +65,24 @@ def handler(request): assert 'Redirect intercepted' in txt +@asyncio.coroutine +def test_no_location_no_intercept(create_server, test_client): + + @asyncio.coroutine + def handler(request): + return web.Response(text="no location", status=301) + + app = yield from create_server() + app.router.add_route('GET', '/', handler) + client = yield from test_client(app) + + resp = yield from client.get('/', allow_redirects=False) + txt = yield from resp.text() + assert 301 == resp.status + assert 'location' not in resp.headers + assert 'no location' in txt + + @asyncio.coroutine def test_intercept_redirects_disabled(create_server, test_client): @asyncio.coroutine