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 1/2] proxmox-http/websocket: remove code for 'text' frames
Date: Mon, 17 May 2021 15:11:00 +0200	[thread overview]
Message-ID: <20210517131101.23490-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210517131101.23490-1-d.csapak@proxmox.com>

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





  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 ` Dominik Csapak [this message]
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

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