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 #174

Merged
merged 2 commits into from
Aug 29, 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
4 changes: 3 additions & 1 deletion aiohttp_debugtoolbar/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down