1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-05-20 09:18:26 +00:00

rename ws::ContinuationItem

This commit is contained in:
Rob Ede 2022-01-24 12:30:31 +00:00
parent 5454699bab
commit 09dcde2612
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
4 changed files with 43 additions and 25 deletions

View file

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

View file

@ -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<Message> 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<Message> 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<Message> 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<Message> 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 {

View file

@ -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};

View file

@ -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());