Skip to content

Commit

Permalink
Solves issue 107
Browse files Browse the repository at this point in the history
  • Loading branch information
jadedevin13 authored Feb 11, 2020
1 parent 1773269 commit dff9827
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/handshake/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,24 @@ pub fn create_response(request: &Request) -> Result<Response> {
.get("Sec-WebSocket-Key")
.ok_or_else(|| Error::Protocol("Missing Sec-WebSocket-Key".into()))?;

let builder = Response::builder()
let protocol_default = HeaderValue::from_static("");

let protocol = request
.headers()
.get("Sec-WebSocket-Protocol")
.unwrap_or(&protocol_default);

let mut builder = Response::builder()
.status(StatusCode::SWITCHING_PROTOCOLS)
.version(request.version())
.header("Connection", "Upgrade")
.header("Upgrade", "websocket")
.header("Sec-WebSocket-Accept", convert_key(key.as_bytes())?);

if !protocol.is_empty() {
builder = builder.header("Sec-WebSocket-Protocol", protocol);
}

Ok(builder.body(())?)
}

Expand Down

0 comments on commit dff9827

Please sign in to comment.