1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

Add WsResponseBuilder to build web socket session response (#1920)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Mohammed Sazid Al Rashid
2021-12-05 04:32:44 +06:00
committed by GitHub
parent fa7f3e6908
commit 4c9ca7196d
5 changed files with 379 additions and 98 deletions

View File

@ -63,8 +63,8 @@ pub enum Item {
Last(Bytes),
}
#[derive(Debug, Copy, Clone)]
/// WebSocket protocol codec.
#[derive(Debug, Clone)]
pub struct Codec {
flags: Flags,
max_size: usize,
@ -89,7 +89,8 @@ impl Codec {
/// Set max frame size.
///
/// By default max size is set to 64kB.
/// By default max size is set to 64KiB.
#[must_use = "This returns the a new Codec, without modifying the original."]
pub fn max_size(mut self, size: usize) -> Self {
self.max_size = size;
self
@ -98,12 +99,19 @@ impl Codec {
/// Set decoder to client mode.
///
/// By default decoder works in server mode.
#[must_use = "This returns the a new Codec, without modifying the original."]
pub fn client_mode(mut self) -> Self {
self.flags.remove(Flags::SERVER);
self
}
}
impl Default for Codec {
fn default() -> Self {
Self::new()
}
}
impl Encoder<Message> for Codec {
type Error = ProtocolError;