1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-18 14:16:47 +00:00

Customize websocket max size

This commit is contained in:
kingxsp 2018-07-11 10:05:43 +08:00
parent 82920e1ac1
commit 5482d64df5

View file

@ -171,18 +171,28 @@ pub enum Message {
}
/// Do websocket handshake and start actor
pub fn start<A, S>(req: &HttpRequest<S>, actor: A) -> Result<HttpResponse, Error>
#[inline]
pub fn create<A, S>(req: &HttpRequest<S>, actor: A, max_size: usize) -> Result<HttpResponse, Error>
where
A: Actor<Context = WebsocketContext<A, S>> + StreamHandler<Message, ProtocolError>,
S: 'static,
{
let mut resp = handshake(req)?;
let stream = WsStream::new(req.payload());
let stream = WsStream::new(req.payload()).max_size(max_size);
let body = WebsocketContext::create(req.clone(), actor, stream);
Ok(resp.body(body))
}
/// Do websocket handshake and start actor
pub fn start<A, S>(req: &HttpRequest<S>, actor: A) -> Result<HttpResponse, Error>
where
A: Actor<Context = WebsocketContext<A, S>> + StreamHandler<Message, ProtocolError>,
S: 'static,
{
create(req, actor, 65_536)
}
/// Prepare `WebSocket` handshake response.
///
/// This function returns handshake `HttpResponse`, ready to send to peer.