From 09dcde26120ef0e5a5ddcc95de6e6c544ef8d428 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 24 Jan 2022 12:30:31 +0000 Subject: [PATCH] rename `ws::ContinuationItem` --- actix-http/CHANGES.md | 3 +++ actix-http/src/ws/codec.rs | 26 +++++++++++++++----------- actix-http/src/ws/mod.rs | 7 ++++--- actix-http/tests/test_ws.rs | 32 +++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 6047a6bc5..115cb9c47 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx +- Rename `ws::{Item => ContinuationItem}`. [#????] + +[#????]: https://github.com/actix/actix-web/pull/???? ## 3.0.0-beta.19 - 2022-01-21 diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs index f5b755eec..861855fef 100644 --- a/actix-http/src/ws/codec.rs +++ b/actix-http/src/ws/codec.rs @@ -17,7 +17,7 @@ pub enum Message { Binary(Bytes), /// Continuation. - Continuation(Item), + Continuation(ContinuationItem), /// Ping message. Ping(Bytes), @@ -42,7 +42,7 @@ pub enum Frame { Binary(Bytes), /// Continuation. - Continuation(Item), + Continuation(ContinuationItem), /// Ping message. Ping(Bytes), @@ -56,13 +56,17 @@ pub enum Frame { /// A WebSocket continuation item. #[derive(Debug, PartialEq)] -pub enum Item { +pub enum ContinuationItem { FirstText(Bytes), FirstBinary(Bytes), Continue(Bytes), Last(Bytes), } +#[doc(hidden)] +#[deprecated(since = "4.0.0", note = "Renamed to `ContinuationItem`.")] +pub type Item = ContinuationItem; + /// WebSocket protocol codec. #[derive(Debug, Clone)] pub struct Codec { @@ -149,7 +153,7 @@ impl Encoder for Codec { Parser::write_close(dst, reason, !self.flags.contains(Flags::SERVER)) } Message::Continuation(cont) => match cont { - Item::FirstText(data) => { + ContinuationItem::FirstText(data) => { if self.flags.contains(Flags::W_CONTINUATION) { return Err(ProtocolError::ContinuationStarted); } else { @@ -163,7 +167,7 @@ impl Encoder for Codec { ) } } - Item::FirstBinary(data) => { + ContinuationItem::FirstBinary(data) => { if self.flags.contains(Flags::W_CONTINUATION) { return Err(ProtocolError::ContinuationStarted); } else { @@ -177,7 +181,7 @@ impl Encoder for Codec { ) } } - Item::Continue(data) => { + ContinuationItem::Continue(data) => { if self.flags.contains(Flags::W_CONTINUATION) { Parser::write_message( dst, @@ -190,7 +194,7 @@ impl Encoder for Codec { return Err(ProtocolError::ContinuationNotStarted); } } - Item::Last(data) => { + ContinuationItem::Last(data) => { if self.flags.contains(Flags::W_CONTINUATION) { self.flags.remove(Flags::W_CONTINUATION); Parser::write_message( @@ -223,7 +227,7 @@ impl Decoder for Codec { return match opcode { OpCode::Continue => { if self.flags.contains(Flags::CONTINUATION) { - Ok(Some(Frame::Continuation(Item::Continue( + Ok(Some(Frame::Continuation(ContinuationItem::Continue( payload.map(|pl| pl.freeze()).unwrap_or_else(Bytes::new), )))) } else { @@ -233,7 +237,7 @@ impl Decoder for Codec { OpCode::Binary => { if !self.flags.contains(Flags::CONTINUATION) { self.flags.insert(Flags::CONTINUATION); - Ok(Some(Frame::Continuation(Item::FirstBinary( + Ok(Some(Frame::Continuation(ContinuationItem::FirstBinary( payload.map(|pl| pl.freeze()).unwrap_or_else(Bytes::new), )))) } else { @@ -243,7 +247,7 @@ impl Decoder for Codec { OpCode::Text => { if !self.flags.contains(Flags::CONTINUATION) { self.flags.insert(Flags::CONTINUATION); - Ok(Some(Frame::Continuation(Item::FirstText( + Ok(Some(Frame::Continuation(ContinuationItem::FirstText( payload.map(|pl| pl.freeze()).unwrap_or_else(Bytes::new), )))) } else { @@ -261,7 +265,7 @@ impl Decoder for Codec { OpCode::Continue => { if self.flags.contains(Flags::CONTINUATION) { self.flags.remove(Flags::CONTINUATION); - Ok(Some(Frame::Continuation(Item::Last( + Ok(Some(Frame::Continuation(ContinuationItem::Last( payload.map(|pl| pl.freeze()).unwrap_or_else(Bytes::new), )))) } else { diff --git a/actix-http/src/ws/mod.rs b/actix-http/src/ws/mod.rs index 568d801a2..b24badbbd 100644 --- a/actix-http/src/ws/mod.rs +++ b/actix-http/src/ws/mod.rs @@ -1,7 +1,7 @@ //! WebSocket protocol implementation. //! -//! To setup a WebSocket, first perform the WebSocket handshake then on success convert `Payload` into a -//! `WsStream` stream and then use `WsWriter` to communicate with the peer. +//! To setup a WebSocket, first perform the WebSocket handshake then on success convert `Payload` +//! into a `WsStream` stream and then use `WsWriter` to communicate with the peer. use std::io; @@ -17,7 +17,8 @@ mod frame; mod mask; mod proto; -pub use self::codec::{Codec, Frame, Item, Message}; +#[allow(deprecated)] // Item is deprecated +pub use self::codec::{Codec, ContinuationItem, Frame, Item, Message}; pub use self::dispatcher::Dispatcher; pub use self::frame::Parser; pub use self::proto::{hash_key, CloseCode, CloseReason, OpCode}; diff --git a/actix-http/tests/test_ws.rs b/actix-http/tests/test_ws.rs index ed8c61fd6..5a9bf8108 100644 --- a/actix-http/tests/test_ws.rs +++ b/actix-http/tests/test_ws.rs @@ -8,7 +8,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Framed}; use actix_http::{ body::{BodySize, BoxBody}, h1, - ws::{self, CloseCode, Frame, Item, Message}, + ws::{self, CloseCode, ContinuationItem, Frame, Message}, Error, HttpService, Request, Response, }; use actix_http_test::test_server; @@ -137,51 +137,61 @@ async fn test_simple() { assert_eq!(item, Frame::Pong("text".to_string().into())); framed - .send(Message::Continuation(Item::FirstText("text".into()))) + .send(Message::Continuation(ContinuationItem::FirstText( + "text".into(), + ))) .await .unwrap(); let item = framed.next().await.unwrap().unwrap(); assert_eq!( item, - Frame::Continuation(Item::FirstText(Bytes::from_static(b"text"))) + Frame::Continuation(ContinuationItem::FirstText(Bytes::from_static(b"text"))) ); assert!(framed - .send(Message::Continuation(Item::FirstText("text".into()))) + .send(Message::Continuation(ContinuationItem::FirstText( + "text".into() + ))) .await .is_err()); assert!(framed - .send(Message::Continuation(Item::FirstBinary("text".into()))) + .send(Message::Continuation(ContinuationItem::FirstBinary( + "text".into() + ))) .await .is_err()); framed - .send(Message::Continuation(Item::Continue("text".into()))) + .send(Message::Continuation(ContinuationItem::Continue( + "text".into(), + ))) .await .unwrap(); let item = framed.next().await.unwrap().unwrap(); assert_eq!( item, - Frame::Continuation(Item::Continue(Bytes::from_static(b"text"))) + Frame::Continuation(ContinuationItem::Continue(Bytes::from_static(b"text"))) ); framed - .send(Message::Continuation(Item::Last("text".into()))) + .send(Message::Continuation(ContinuationItem::Last("text".into()))) .await .unwrap(); let item = framed.next().await.unwrap().unwrap(); assert_eq!( item, - Frame::Continuation(Item::Last(Bytes::from_static(b"text"))) + Frame::Continuation(ContinuationItem::Last(Bytes::from_static(b"text"))) ); assert!(framed - .send(Message::Continuation(Item::Continue("text".into()))) + .send(Message::Continuation(ContinuationItem::Continue( + "text".into() + ))) .await .is_err()); assert!(framed - .send(Message::Continuation(Item::Last("text".into()))) + .send(Message::Continuation(ContinuationItem::Last("text".into()))) .await .is_err());