[pbs-devel] [PATCH proxmox 1/2] proxmox-http/websocket: remove code for 'text' frames

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


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






More information about the pbs-devel mailing list