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

Accept yarl in redirections #1278

Merged
merged 3 commits into from
Sep 30, 2016
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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CHANGES
`web.Request.url` are added. URLs and templates are percent-encoded
now. #1224

-
- Accept `yarl.URL` by server redirections #1278

-

Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, location, *, headers=None, reason=None,
raise ValueError("HTTP redirects need a location to redirect to.")
super().__init__(headers=headers, reason=reason,
body=body, text=text, content_type=content_type)
self.headers['Location'] = location
self.headers['Location'] = str(location)
self.location = location


Expand Down
21 changes: 21 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytest
from multidict import MultiDict
from yarl import URL

from aiohttp import FormData, multipart, web
from aiohttp.protocol import HttpVersion, HttpVersion10, HttpVersion11
Expand Down Expand Up @@ -838,3 +839,23 @@ def handler(request):
resp = yield from client.get('/')
assert 200 == resp.status
assert client.handler.requests_count == 3


@asyncio.coroutine
def test_redirect_url(loop, test_client):

@asyncio.coroutine
def redirector(request):
raise web.HTTPFound(location=URL('/redirected'))

@asyncio.coroutine
def redirected(request):
return web.Response()

app = web.Application(loop=loop)
app.router.add_get('/redirector', redirector)
app.router.add_get('/redirected', redirected)

client = yield from test_client(app)
resp = yield from client.get('/redirector')
assert resp.status == 200