Skip to content

Commit

Permalink
Merge pull request #2920 from ploxiln/websocket_no_redirect
Browse files Browse the repository at this point in the history
websocket: set follow_redirects to False
  • Loading branch information
bdarnell authored Sep 25, 2020
2 parents 894c8a4 + 3e13fd2 commit 5a069a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 5a069a8

Please sign in to comment.