Created
February 1, 2021 19:03
-
-
Save tsidea/711b26602458ed34bd5d6bcecb1da4b2 to your computer and use it in GitHub Desktop.
create websocket hanshake response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tungstenite::{handshake, Error}; | |
... | |
match handshake::server::create_response_with_body(&request, || Body::empty()) { | |
Ok(response) => { | |
//handle websocket connection HERE | |
... | |
//return the response to the handshake request | |
response | |
}, | |
Err(error) => { | |
//probably the handshake request is not up to spec for websocket | |
println!("Failed to create websocket response \ | |
to request from address {}. \ | |
Error is: {}", remote_addr, error); | |
let mut res = Response::new(Body::from(format!("Failed to create websocket: {}", error))); | |
*res.status_mut() = StatusCode::BAD_REQUEST; | |
return Ok(res); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment