From ce34eab832e6c9514c0282dadfe1060bf76aeb7c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 29 Oct 2017 14:50:26 -0700 Subject: [PATCH] better ws handshake error responses --- src/ws.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ws.rs b/src/ws.rs index f39489a6b..359400422 100644 --- a/src/ws.rs +++ b/src/ws.rs @@ -116,7 +116,11 @@ impl ResponseType for Message { pub fn handshake(req: &HttpRequest) -> Result { // WebSocket accepts only GET if *req.method() != Method::GET { - return Err(HTTPMethodNotAllowed.response()) + return Err( + HTTPMethodNotAllowed + .builder() + .header(header::ALLOW, "GET") + .finish()?) } // Check for "UPGRADE" to websocket header @@ -130,7 +134,7 @@ pub fn handshake(req: &HttpRequest) -> Result { false }; if !has_hdr { - return Err(HTTPMethodNotAllowed.with_reason("No WebSocket UPGRADE header found")) + return Err(HTTPBadRequest.with_reason("No WebSocket UPGRADE header found")) } // Upgrade connection