diff --git a/tornado/test/websocket_test.py b/tornado/test/websocket_test.py index 766b14b861..befe06dd39 100644 --- a/tornado/test/websocket_test.py +++ b/tornado/test/websocket_test.py @@ -111,6 +111,11 @@ def get(self): self.write("ok") +class RedirectHandler(RequestHandler): + def get(self): + self.redirect("/echo") + + class CloseReasonHandler(TestWebSocketHandler): def open(self): self.on_close_called = False @@ -221,6 +226,7 @@ def get_app(self): [ ("/echo", EchoHandler, dict(close_future=self.close_future)), ("/non_ws", NonWebSocketHandler), + ("/redirect", RedirectHandler), ("/header", HeaderHandler, dict(close_future=self.close_future)), ( "/header_echo", @@ -365,6 +371,11 @@ def test_websocket_http_success(self): with self.assertRaises(WebSocketError): yield self.ws_connect("/non_ws") + @gen_test + def test_websocket_http_redirect(self): + with self.assertRaises(HTTPError): + yield self.ws_connect("/redirect") + @gen_test def test_websocket_network_fail(self): sock, port = bind_unused_port() diff --git a/tornado/websocket.py b/tornado/websocket.py index ff0c241614..eef49e7c99 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -1409,6 +1409,9 @@ def __init__( "Sec-WebSocket-Extensions" ] = "permessage-deflate; client_max_window_bits" + # Websocket connection is currently unable to follow redirects + request.follow_redirects = False + self.tcp_client = TCPClient() super().__init__( None,