From 0786b4b98ca09fba3c062bfc9be016c626b7f6f2 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 17 May 2021 15:11:01 +0200 Subject: [PATCH] proxmox-http/websocket: remove subprotocol handling we do not support websocket subprotocols, but for compatibility with current clients (novnc, pve-xtermjs) we have to reply with the one requested, else this is a protocol error and browsers will error out Signed-off-by: Dominik Csapak --- proxmox-http/src/websocket/mod.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/proxmox-http/src/websocket/mod.rs b/proxmox-http/src/websocket/mod.rs index e6ab998f..d15c8c52 100644 --- a/proxmox-http/src/websocket/mod.rs +++ b/proxmox-http/src/websocket/mod.rs @@ -671,13 +671,6 @@ impl WebSocket { .ok_or_else(|| format_err!("missing websocket key"))? .to_str()?; - let ws_proto = headers - .get(SEC_WEBSOCKET_PROTOCOL) - .ok_or_else(|| format_err!("missing websocket key"))? - .to_str()?; - - let text = ws_proto == "text"; - if protocols != "websocket" { bail!("invalid protocol name"); } @@ -693,13 +686,19 @@ impl WebSocket { sha1.update(data.as_bytes()); let response_key = base64::encode(sha1.finish()); - let response = Response::builder() + let mut response = Response::builder() .status(StatusCode::SWITCHING_PROTOCOLS) .header(UPGRADE, HeaderValue::from_static("websocket")) .header(CONNECTION, HeaderValue::from_static("Upgrade")) - .header(SEC_WEBSOCKET_ACCEPT, response_key) - .header(SEC_WEBSOCKET_PROTOCOL, ws_proto) - .body(Body::empty())?; + .header(SEC_WEBSOCKET_ACCEPT, response_key); + + // We currently do not support any subprotocols and we always send binary frames, + // but for backwards compatibilty we need to reply the requested protocols + if let Some(ws_proto) = headers.get(SEC_WEBSOCKET_PROTOCOL) { + response = response.header(SEC_WEBSOCKET_PROTOCOL, ws_proto) + } + + let response = response.body(Body::empty())?; Ok((Self, response)) }