|
|
|
@ -195,7 +195,7 @@ pub struct ServerHandshake<S, C> { |
|
|
|
|
/// WebSocket configuration.
|
|
|
|
|
config: Option<WebSocketConfig>, |
|
|
|
|
/// 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.
|
|
|
|
|
_marker: PhantomData<S>, |
|
|
|
|
} |
|
|
|
@ -212,7 +212,7 @@ impl<S: Read + Write, C: Callback> ServerHandshake<S, C> { |
|
|
|
|
role: ServerHandshake { |
|
|
|
|
callback: Some(callback), |
|
|
|
|
config, |
|
|
|
|
error_code: None, |
|
|
|
|
error_response: None, |
|
|
|
|
_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![]; |
|
|
|
|
write_response(&mut output, &resp)?; |
|
|
|
|
|
|
|
|
|
if let Some(body) = resp.body() { |
|
|
|
|
output.extend_from_slice(body.as_bytes()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ProcessingResult::Continue(HandshakeMachine::start_write(stream, output)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StageResult::DoneWriting(stream) => { |
|
|
|
|
if let Some(err) = self.error_code.take() { |
|
|
|
|
if let Some(err) = self.error_response.take() { |
|
|
|
|
debug!("Server handshake failed."); |
|
|
|
|
return Err(Error::HttpStatus(StatusCode::from_u16(err)?)); |
|
|
|
|
return Err(Error::Http(err)); |
|
|
|
|
} else { |
|
|
|
|
debug!("Server handshake done."); |
|
|
|
|
let websocket = WebSocket::from_raw_socket(stream, Role::Server, self.config); |
|
|
|
|