|
|
@ -195,7 +195,7 @@ pub struct ServerHandshake<S, C> { |
|
|
|
/// WebSocket configuration.
|
|
|
|
/// WebSocket configuration.
|
|
|
|
config: Option<WebSocketConfig>, |
|
|
|
config: Option<WebSocketConfig>, |
|
|
|
/// Error code/flag. If set, an error will be returned after sending response to the client.
|
|
|
|
/// Error code/flag. If set, an error will be returned after sending response to the client.
|
|
|
|
error_code: Option<u16>, |
|
|
|
error_response: Option<ErrorResponse>, |
|
|
|
/// Internal stream type.
|
|
|
|
/// Internal stream type.
|
|
|
|
_marker: PhantomData<S>, |
|
|
|
_marker: PhantomData<S>, |
|
|
|
} |
|
|
|
} |
|
|
@ -212,7 +212,7 @@ impl<S: Read + Write, C: Callback> ServerHandshake<S, C> { |
|
|
|
role: ServerHandshake { |
|
|
|
role: ServerHandshake { |
|
|
|
callback: Some(callback), |
|
|
|
callback: Some(callback), |
|
|
|
config, |
|
|
|
config, |
|
|
|
error_code: None, |
|
|
|
error_response: None, |
|
|
|
_marker: PhantomData, |
|
|
|
_marker: PhantomData, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
@ -259,22 +259,25 @@ impl<S: Read + Write, C: Callback> HandshakeRole for ServerHandshake<S, C> { |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.error_code = Some(resp.status().as_u16()); |
|
|
|
self.error_response = Some(resp); |
|
|
|
|
|
|
|
let resp = self.error_response.as_ref().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let mut output = vec![]; |
|
|
|
let mut output = vec![]; |
|
|
|
write_response(&mut output, &resp)?; |
|
|
|
write_response(&mut output, &resp)?; |
|
|
|
|
|
|
|
|
|
|
|
if let Some(body) = resp.body() { |
|
|
|
if let Some(body) = resp.body() { |
|
|
|
output.extend_from_slice(body.as_bytes()); |
|
|
|
output.extend_from_slice(body.as_bytes()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ProcessingResult::Continue(HandshakeMachine::start_write(stream, output)) |
|
|
|
ProcessingResult::Continue(HandshakeMachine::start_write(stream, output)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StageResult::DoneWriting(stream) => { |
|
|
|
StageResult::DoneWriting(stream) => { |
|
|
|
if let Some(err) = self.error_code.take() { |
|
|
|
if let Some(err) = self.error_response.take() { |
|
|
|
debug!("Server handshake failed."); |
|
|
|
debug!("Server handshake failed."); |
|
|
|
return Err(Error::HttpStatus(StatusCode::from_u16(err)?)); |
|
|
|
return Err(Error::Http(err)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
debug!("Server handshake done."); |
|
|
|
debug!("Server handshake done."); |
|
|
|
let websocket = WebSocket::from_raw_socket(stream, Role::Server, self.config); |
|
|
|
let websocket = WebSocket::from_raw_socket(stream, Role::Server, self.config); |
|
|
|