public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling
Date: Mon, 17 May 2021 15:11:01 +0200	[thread overview]
Message-ID: <20210517131101.23490-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210517131101.23490-1-d.csapak@proxmox.com>

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@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





  parent reply	other threads:[~2021-05-17 13:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17 13:10 [pbs-devel] [PATCH proxmox 0/2] remove unnecessary websocket code Dominik Csapak
2021-05-17 13:11 ` [pbs-devel] [PATCH proxmox 1/2] proxmox-http/websocket: remove code for 'text' frames Dominik Csapak
2021-05-17 13:11 ` Dominik Csapak [this message]
2021-05-18  8:33 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] remove unnecessary websocket code Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210517131101.23490-3-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal