mirror of https://github.com/fafhrd91/actix-web
Make correct ping handeling a flag
This commit is contained in:
parent
c5dfead7f9
commit
81230a7cb1
|
@ -23,7 +23,8 @@ name = "actix_http"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["invalid-ping-payload"]
|
||||||
|
invalid-ping-payload = []
|
||||||
|
|
||||||
# openssl
|
# openssl
|
||||||
ssl = ["openssl", "actix-connect/ssl"]
|
ssl = ["openssl", "actix-connect/ssl"]
|
||||||
|
|
|
@ -13,8 +13,14 @@ pub enum Message {
|
||||||
/// Binary message
|
/// Binary message
|
||||||
Binary(Bytes),
|
Binary(Bytes),
|
||||||
/// Ping message
|
/// Ping message
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
Ping(String),
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
Ping(Bytes),
|
Ping(Bytes),
|
||||||
/// Pong message
|
/// Pong message
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
Pong(String),
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
Pong(Bytes),
|
Pong(Bytes),
|
||||||
/// Close message with optional reason
|
/// Close message with optional reason
|
||||||
Close(Option<CloseReason>),
|
Close(Option<CloseReason>),
|
||||||
|
@ -30,8 +36,14 @@ pub enum Frame {
|
||||||
/// Binary frame
|
/// Binary frame
|
||||||
Binary(Option<BytesMut>),
|
Binary(Option<BytesMut>),
|
||||||
/// Ping message
|
/// Ping message
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
Ping(String),
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
Ping(Bytes),
|
Ping(Bytes),
|
||||||
/// Pong message
|
/// Pong message
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
Pong(String),
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
Pong(Bytes),
|
Pong(Bytes),
|
||||||
/// Close message with optional reason
|
/// Close message with optional reason
|
||||||
Close(Option<CloseReason>),
|
Close(Option<CloseReason>),
|
||||||
|
@ -190,6 +202,7 @@ impl Decoder for Codec {
|
||||||
Ok(Some(Frame::Close(None)))
|
Ok(Some(Frame::Close(None)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
OpCode::Ping => {
|
OpCode::Ping => {
|
||||||
if let Some(pl) = payload {
|
if let Some(pl) = payload {
|
||||||
Ok(Some(Frame::Ping(pl.into())))
|
Ok(Some(Frame::Ping(pl.into())))
|
||||||
|
@ -197,6 +210,7 @@ impl Decoder for Codec {
|
||||||
Ok(Some(Frame::Ping(Bytes::new())))
|
Ok(Some(Frame::Ping(Bytes::new())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
OpCode::Pong => {
|
OpCode::Pong => {
|
||||||
if let Some(pl) = payload {
|
if let Some(pl) = payload {
|
||||||
Ok(Some(Frame::Pong(pl.into())))
|
Ok(Some(Frame::Pong(pl.into())))
|
||||||
|
@ -204,6 +218,22 @@ impl Decoder for Codec {
|
||||||
Ok(Some(Frame::Pong(Bytes::new())))
|
Ok(Some(Frame::Pong(Bytes::new())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
OpCode::Ping => {
|
||||||
|
if let Some(ref pl) = payload {
|
||||||
|
Ok(Some(Frame::Ping(String::from_utf8_lossy(pl).into())))
|
||||||
|
} else {
|
||||||
|
Ok(Some(Frame::Ping(String::new())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
OpCode::Pong => {
|
||||||
|
if let Some(ref pl) = payload {
|
||||||
|
Ok(Some(Frame::Pong(String::from_utf8_lossy(pl).into())))
|
||||||
|
} else {
|
||||||
|
Ok(Some(Frame::Pong(String::new())))
|
||||||
|
}
|
||||||
|
}
|
||||||
OpCode::Binary => Ok(Some(Frame::Binary(payload))),
|
OpCode::Binary => Ok(Some(Frame::Binary(payload))),
|
||||||
OpCode::Text => {
|
OpCode::Text => {
|
||||||
Ok(Some(Frame::Text(payload)))
|
Ok(Some(Frame::Text(payload)))
|
||||||
|
|
|
@ -17,6 +17,10 @@ edition = "2018"
|
||||||
name = "actix_web_actors"
|
name = "actix_web_actors"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["invalid-ping-payload"]
|
||||||
|
invalid-ping-payload = ["actix-http/invalid-ping-payload"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.8.3"
|
actix = "0.8.3"
|
||||||
actix-web = "1.0.3"
|
actix-web = "1.0.3"
|
||||||
|
|
|
@ -345,15 +345,31 @@ where
|
||||||
|
|
||||||
/// Send ping frame
|
/// Send ping frame
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
pub fn ping<B: Into<Bytes>>(&mut self, message: B) {
|
pub fn ping<B: Into<Bytes>>(&mut self, message: B) {
|
||||||
self.write_raw(Message::Ping(message.into()));
|
self.write_raw(Message::Ping(message.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send ping frame
|
||||||
|
#[inline]
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
pub fn ping<B: Into<Bytes>>(&mut self, message: &str) {
|
||||||
|
self.write_raw(Message::Ping(message.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
/// Send pong frame
|
/// Send pong frame
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg(not(feature = "invalid-ping-payload"))]
|
||||||
pub fn pong<B: Into<Bytes>>(&mut self, message: B) {
|
pub fn pong<B: Into<Bytes>>(&mut self, message: B) {
|
||||||
self.write_raw(Message::Pong(message.into()));
|
self.write_raw(Message::Pong(message.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send pong frame
|
||||||
|
#[inline]
|
||||||
|
#[cfg(feature = "invalid-ping-payload")]
|
||||||
|
pub fn pong(&mut self, message: &str) {
|
||||||
|
self.write_raw(Message::Pong(message.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
/// Send close frame
|
/// Send close frame
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in New Issue