1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-26 15:07:42 +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

@ -9,6 +9,8 @@
* `body::None` struct. [#2468]
* Impl `MessageBody` for `bytestring::ByteString`. [#2468]
* `impl Clone for ws::HandshakeError`. [#2468]
* `#[must_use]` for `ws::Codec` to prevent subtle bugs. [#1920]
* `impl Default ` for `ws::Codec`. [#1920]
### Changed
* Rename `body::BoxBody::{from_body => new}`. [#2468]
@ -24,9 +26,11 @@
* `impl Future` for `ResponseBuilder`. [#2468]
* Remove unnecessary `MessageBody` bound on types passed to `body::AnyBody::new`. [#2468]
* Move `body::AnyBody` to `awc`. Replaced with `EitherBody` and `BoxBody`. [#2468]
* `impl Copy` for `ws::Codec`. [#1920]
[#2483]: https://github.com/actix/actix-web/pull/2483
[#2468]: https://github.com/actix/actix-web/pull/2468
[#1920]: https://github.com/actix/actix-web/pull/1920
## 3.0.0-beta.14 - 2021-11-30

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;