diff --git a/actix-web-actors/src/ws.rs b/actix-web-actors/src/ws.rs index 0ef3c9169..c6bc440c8 100644 --- a/actix-web-actors/src/ws.rs +++ b/actix-web-actors/src/ws.rs @@ -31,7 +31,24 @@ where A: Actor> + StreamHandler, T: Stream + 'static, { - let mut res = handshake(req)?; + let mut res = handshake(req, &vec![])?; + Ok(res.streaming(WebsocketContext::create(actor, stream))) +} + +/// Do websocket handshake and start ws actor. +/// +/// `protocols` is a sequence of known protocols. +pub fn start_with_protocols( + actor: A, + protocols: &Vec<&str>, + req: &HttpRequest, + stream: T, +) -> Result +where + A: Actor> + StreamHandler, + T: Stream + 'static, +{ + let mut res = handshake(req, protocols)?; Ok(res.streaming(WebsocketContext::create(actor, stream))) } @@ -40,10 +57,13 @@ where /// This function returns handshake `HttpResponse`, ready to send to peer. /// It does not perform any IO. /// -// /// `protocols` is a sequence of known protocols. On successful handshake, -// /// the returned response headers contain the first protocol in this list -// /// which the server also knows. -pub fn handshake(req: &HttpRequest) -> Result { +/// `protocols` is a sequence of known protocols. On successful handshake, +/// the returned response headers contain the first protocol in this list +/// which the server also knows. +pub fn handshake( + req: &HttpRequest, + protocols: &Vec<&str>, +) -> Result { // WebSocket accepts only GET if *req.method() != Method::GET { return Err(HandshakeError::GetMethodRequired); @@ -92,11 +112,28 @@ pub fn handshake(req: &HttpRequest) -> Result