From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 304AB710B9 for ; Mon, 17 May 2021 15:11:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 23ACA2C249 for ; Mon, 17 May 2021 15:11:07 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 512A42C22D for ; Mon, 17 May 2021 15:11:02 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 23291465C1 for ; Mon, 17 May 2021 15:11:02 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 17 May 2021 15:11:01 +0200 Message-Id: <20210517131101.23490-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210517131101.23490-1-d.csapak@proxmox.com> References: <20210517131101.23490-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 13:11:37 -0000 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 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