return (
self.code in (301, 302, 303, 307, 308)
and self.request.max_redirects > 0
+ and self.headers is not None
+ and self.headers.get("Location") is not None
)
return False
)
+class RedirectWithoutLocationHandler(RequestHandler):
+ def prepare(self):
+ # For testing error handling of a redirect with no location header.
+ self.set_status(301)
+ self.finish()
+
+
class ChunkHandler(RequestHandler):
@gen.coroutine
def get(self):
url("/post", PostHandler),
url("/put", PutHandler),
url("/redirect", RedirectHandler),
+ url("/redirect_without_location", RedirectWithoutLocationHandler),
url("/chunk", ChunkHandler),
url("/auth", AuthHandler),
url("/countdown/([0-9]+)", CountdownHandler, name="countdown"),
self.assertTrue(response.effective_url.endswith("/countdown/0"))
self.assertEqual(b"Zero", response.body)
+ def test_redirect_without_location(self):
+ response = self.fetch("/redirect_without_location", follow_redirects=True)
+ # If there is no location header, the redirect response should
+ # just be returned as-is. (This should arguably raise an
+ # error, but libcurl doesn't treat this as an error, so we
+ # don't either).
+ self.assertEqual(301, response.code)
+
def test_credentials_in_url(self):
url = self.get_url("/auth").replace("http://", "http://me:secret@")
response = self.fetch(url)