[pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling

Dominik Csapak d.csapak at proxmox.com
Mon May 17 15:11:01 CEST 2021


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 <d.csapak at proxmox.com>
---
 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 e6ab998..d15c8c5 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))
     }
-- 
2.20.1






More information about the pbs-devel mailing list