* [pbs-devel] [PATCH proxmox 0/2] remove unnecessary websocket code
@ 2021-05-17 13:10 Dominik Csapak
2021-05-17 13:11 ` [pbs-devel] [PATCH proxmox 1/2] proxmox-http/websocket: remove code for 'text' frames Dominik Csapak
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-05-17 13:10 UTC (permalink / raw)
To: pbs-devel
similar reasoning as for pve[0] but here we only have to consider
xtermjs
same rules for compat/client code applies, if we apply for 1.x we
can drop the client protocol in 2.0 and compat in 3.0
else the client code in 3.0 and compat code in 4.0
we only have to make sure that we do that in lockstep with pve/pmg,
since they share pve-xtermjs
0: https://lists.proxmox.com/pipermail/pve-devel/2021-May/048216.html
Dominik Csapak (2):
proxmox-http/websocket: remove code for 'text' frames
proxmox-http/websocket: remove subprotocol handling
proxmox-http/src/websocket/mod.rs | 39 ++++++++++++-------------------
1 file changed, 15 insertions(+), 24 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox 1/2] proxmox-http/websocket: remove code for 'text' frames
2021-05-17 13:10 [pbs-devel] [PATCH proxmox 0/2] remove unnecessary websocket code Dominik Csapak
@ 2021-05-17 13:11 ` Dominik Csapak
2021-05-17 13:11 ` [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling Dominik Csapak
2021-05-18 8:33 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] remove unnecessary websocket code Fabian Grünbichler
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-05-17 13:11 UTC (permalink / raw)
To: pbs-devel
we never actually sent text frames, nor did any client request them.
Also, no validity check ever ocurred, so technically it was against
the spec.
Simply remove the code handling sending out text frames. If we need
to actually handle that, we can always create a 'WebSocketStringWriter'
or similar.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-http/src/websocket/mod.rs | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/proxmox-http/src/websocket/mod.rs b/proxmox-http/src/websocket/mod.rs
index b8f31dc..e6ab998 100644
--- a/proxmox-http/src/websocket/mod.rs
+++ b/proxmox-http/src/websocket/mod.rs
@@ -243,7 +243,6 @@ pub fn create_frame(
/// ```
pub struct WebSocketWriter<W: AsyncWrite + Unpin> {
writer: W,
- text: bool,
mask: Option<[u8; 4]>,
frame: Option<(Vec<u8>, usize, usize)>,
}
@@ -251,10 +250,9 @@ pub struct WebSocketWriter<W: AsyncWrite + Unpin> {
impl<W: AsyncWrite + Unpin> WebSocketWriter<W> {
/// Creates a new WebSocketWriter which will use the given mask (if any),
/// and mark the frames as either 'Text' or 'Binary'
- pub fn new(mask: Option<[u8; 4]>, text: bool, writer: W) -> WebSocketWriter<W> {
+ pub fn new(mask: Option<[u8; 4]>, writer: W) -> WebSocketWriter<W> {
WebSocketWriter {
writer,
- text,
mask,
frame: None,
}
@@ -275,11 +273,7 @@ impl<W: AsyncWrite + Unpin> AsyncWrite for WebSocketWriter<W> {
fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<io::Result<usize>> {
let this = Pin::get_mut(self);
- let frametype = if this.text {
- OpCode::Text
- } else {
- OpCode::Binary
- };
+ let frametype = OpCode::Binary;
if this.frame.is_none() {
// create frame buf
@@ -656,9 +650,7 @@ impl<R: AsyncRead + Unpin + Send + 'static> AsyncRead for WebSocketReader<R> {
pub const MAGIC_WEBSOCKET_GUID: &str = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
/// Provides methods for connecting a WebSocket endpoint with another
-pub struct WebSocket {
- text: bool,
-}
+pub struct WebSocket;
impl WebSocket {
/// Returns a new WebSocket instance and the generates the correct
@@ -709,7 +701,7 @@ impl WebSocket {
.header(SEC_WEBSOCKET_PROTOCOL, ws_proto)
.body(Body::empty())?;
- Ok((Self { text }, response))
+ Ok((Self, response))
}
async fn handle_channel_message<W>(
@@ -798,7 +790,7 @@ impl WebSocket {
let (tx, mut rx) = mpsc::unbounded_channel();
let mut wsreader = WebSocketReader::new(usreader, tx);
- let mut wswriter = WebSocketWriter::new(None, self.text, uswriter);
+ let mut wswriter = WebSocketWriter::new(None, uswriter);
let ws_future = tokio::io::copy(&mut wsreader, &mut dswriter);
let term_future = Self::copy_to_websocket(&mut dsreader, &mut wswriter, &mut rx);
--
2.20.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling
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
2021-05-18 8:33 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] remove unnecessary websocket code Fabian Grünbichler
2 siblings, 0 replies; 4+ messages in thread
From: Dominik Csapak @ 2021-05-17 13:11 UTC (permalink / raw)
To: pbs-devel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied-series: [PATCH proxmox 0/2] remove unnecessary websocket code
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 ` [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling Dominik Csapak
@ 2021-05-18 8:33 ` Fabian Grünbichler
2 siblings, 0 replies; 4+ messages in thread
From: Fabian Grünbichler @ 2021-05-18 8:33 UTC (permalink / raw)
To: Proxmox Backup Server development discussion
On May 17, 2021 3:10 pm, Dominik Csapak wrote:
> similar reasoning as for pve[0] but here we only have to consider
> xtermjs
>
> same rules for compat/client code applies, if we apply for 1.x we
> can drop the client protocol in 2.0 and compat in 3.0
> else the client code in 3.0 and compat code in 4.0
>
> we only have to make sure that we do that in lockstep with pve/pmg,
> since they share pve-xtermjs
>
> 0: https://lists.proxmox.com/pipermail/pve-devel/2021-May/048216.html
>
> Dominik Csapak (2):
> proxmox-http/websocket: remove code for 'text' frames
> proxmox-http/websocket: remove subprotocol handling
>
> proxmox-http/src/websocket/mod.rs | 39 ++++++++++++-------------------
> 1 file changed, 15 insertions(+), 24 deletions(-)
>
> --
> 2.20.1
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-18 8:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [pbs-devel] [PATCH proxmox 2/2] proxmox-http/websocket: remove subprotocol handling Dominik Csapak
2021-05-18 8:33 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] remove unnecessary websocket code Fabian Grünbichler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox