From a3ce371312c12fb70d855d85a5ede2b98504ffa1 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 9 Dec 2019 07:01:22 +0600 Subject: [PATCH] ws ping and pong uses bytes #1049 --- Cargo.toml | 2 +- actix-http/CHANGES.md | 5 +++++ actix-http/src/ws/codec.rs | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 93d8ef1a..65f8df2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,7 +78,7 @@ actix-tls = { version = "1.0.0-alpha.3" } actix-web-codegen = "0.2.0-alpha.2" actix-http = "1.0.0-alpha.4" -awc = { version = "1.0.0-alpha.3", default-features = false, optional = true } +awc = { version = "1.0.0-alpha.4", default-features = false, optional = true } bytes = "0.5.2" derive_more = "0.99.2" diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 4349417c..b15a0c65 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,10 @@ # Changes + +### Changed + +* Websockets: Ping and Pong should have binary data #1049 + ## [1.0.0-alpha.4] - 2019-12-08 ### Added diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs index 9891bfa6..fee8a632 100644 --- a/actix-http/src/ws/codec.rs +++ b/actix-http/src/ws/codec.rs @@ -13,9 +13,9 @@ pub enum Message { /// Binary message Binary(Bytes), /// Ping message - Ping(String), + Ping(Bytes), /// Pong message - Pong(String), + Pong(Bytes), /// Close message with optional reason Close(Option), /// No-op. Useful for actix-net services @@ -30,9 +30,9 @@ pub enum Frame { /// Binary frame Binary(Option), /// Ping message - Ping(String), + Ping(Bytes), /// Pong message - Pong(String), + Pong(Bytes), /// Close message with optional reason Close(Option), } @@ -119,17 +119,17 @@ impl Decoder for Codec { } } OpCode::Ping => { - if let Some(ref pl) = payload { - Ok(Some(Frame::Ping(String::from_utf8_lossy(pl).into()))) + if let Some(pl) = payload { + Ok(Some(Frame::Ping(pl.freeze()))) } else { - Ok(Some(Frame::Ping(String::new()))) + Ok(Some(Frame::Ping(Bytes::new()))) } } OpCode::Pong => { - if let Some(ref pl) = payload { - Ok(Some(Frame::Pong(String::from_utf8_lossy(pl).into()))) + if let Some(pl) = payload { + Ok(Some(Frame::Pong(pl.freeze()))) } else { - Ok(Some(Frame::Pong(String::new()))) + Ok(Some(Frame::Pong(Bytes::new()))) } } OpCode::Binary => Ok(Some(Frame::Binary(payload))),