Skip to content

Commit

Permalink
Accept yarl in redirections (#1278)
Browse files Browse the repository at this point in the history
* Accept yarl by redirections

* Add a PR number to CHANGES

* Fix grammar
  • Loading branch information
asvetlov authored Sep 30, 2016
1 parent 3650d8d commit b85b4c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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

0 comments on commit b85b4c2

Please sign in to comment.