Skip to content
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
11 changes: 11 additions & 0 deletions tornado/test/websocket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tornado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down