Skip to content

Commit

Permalink
Warn if proxied websockets' selected subprotocols mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Feb 23, 2024
1 parent e59c7ba commit eda6136
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions jupyter_server_proxy/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ async def start_websocket_connection():
)
self._record_activity()
self.log.info(f"Websocket connection established to {client_uri}")
if (
subprotocols
and self.ws.selected_subprotocol != self.selected_subprotocol
):
self.log.warn(
f"Websocket subprotocol between proxy/server ({self.ws.selected_subprotocol}) "
f"became different than for client/proxy ({self.selected_subprotocol}) "
"due to https://github.com/jupyterhub/jupyter-server-proxy/issues/459. "
f"Requested subprotocols were {subprotocols}."
)

# Wait for the WebSocket to be connected before resolving.
# Otherwise, messages sent by the client before the
Expand Down Expand Up @@ -539,7 +549,8 @@ def select_subprotocol(self, subprotocols):
Note that this subprotocol selection should really be delegated to the
server we proxy to, but we don't! For this to happen, we would need to
delay accepting the handshake with the client until we have successfully
handshaked with the server.
handshaked with the server. This issue is tracked via
https://github.com/jupyterhub/jupyter-server-proxy/issues/459.
Overrides `tornado.websocket.WebSocketHandler.select_subprotocol` that
includes an informative docstring:
Expand All @@ -549,7 +560,6 @@ def select_subprotocol(self, subprotocols):
self.log.debug(
f"Client sent subprotocols: {subprotocols}, selecting the first"
)
# TODO: warn if we select one out of multiple!
return subprotocols[0]
return None

Expand Down

0 comments on commit eda6136

Please sign in to comment.