From 6cea3c70d19c07316a664c407284f6d6957d8852 Mon Sep 17 00:00:00 2001 From: Mohammed Sazid Al Rashid Date: Mon, 4 Jan 2021 22:18:16 +0600 Subject: [PATCH 1/3] add fn's to start ws with frame size and codec --- actix-web-actors/src/ws.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index 60942c6c6..999ddbda8 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -40,6 +40,43 @@ where Ok(res.streaming(WebsocketContext::create(actor, stream))) } +/// Perform WebSocket handshake and start actor with the given frame size. +pub fn start_with_frame_size( + actor: A, + req: &HttpRequest, + stream: T, + frame_size: usize, +) -> Result +where + A: Actor> + + StreamHandler>, + T: Stream> + 'static, +{ + let mut res = handshake(req)?; + Ok(res.streaming(WebsocketContext::with_codec( + actor, + stream, + Codec::new().max_size(frame_size), + ))) +} + +/// Perform WebSocket handshake and start actor with the given +/// `actix_http::ws::Codec`. +pub fn start_with_codec( + actor: A, + req: &HttpRequest, + stream: T, + codec: Codec, +) -> Result +where + A: Actor> + + StreamHandler>, + T: Stream> + 'static, +{ + let mut res = handshake(req)?; + Ok(res.streaming(WebsocketContext::with_codec(actor, stream, codec))) +} + /// Perform WebSocket handshake and start actor. /// /// `req` is an HTTP Request that should be requesting a websocket protocol From cbc9ba1734dc1607e94581903587bd22f2490679 Mon Sep 17 00:00:00 2001 From: Mohammed Sazid Al Rashid Date: Mon, 4 Jan 2021 23:05:15 +0600 Subject: [PATCH 2/3] update changelog --- actix-web-actors/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actix-web-actors/CHANGES.md b/actix-web-actors/CHANGES.md index dab35953a..8f7cb012c 100644 --- a/actix-web-actors/CHANGES.md +++ b/actix-web-actors/CHANGES.md @@ -4,6 +4,8 @@ * Update `pin-project` to `1.0`. * Update `bytes` to `1.0`. [#1813] * `WebsocketContext::text` now takes an `Into`. [#1864] +* Add `ws::start_with_frame_size()` and `ws::start_with_codec()` to start + websocket actor with a given frame size or a `actix_http::ws::Codec`. [#1873] [#1813]: https://github.com/actix/actix-web/pull/1813 [#1864]: https://github.com/actix/actix-web/pull/1864 From bbe729a5dc9b04944011d2dc069008c605b27bf6 Mon Sep 17 00:00:00 2001 From: Mohammed Sazid Al Rashid Date: Tue, 5 Jan 2021 12:06:11 +0600 Subject: [PATCH 3/3] Use intra-doc links. Co-authored-by: Rob Ede --- actix-web-actors/src/ws.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index 999ddbda8..b0969bb63 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -60,8 +60,7 @@ where ))) } -/// Perform WebSocket handshake and start actor with the given -/// `actix_http::ws::Codec`. +/// Perform WebSocket handshake and start actor with the given [`Codec`]. pub fn start_with_codec( actor: A, req: &HttpRequest,