body of error response is buffer

nextgraph
Niko PLP 1 year ago
parent b9eae28e30
commit ca220b1ee0
  1. 9
      src/handshake/server.rs

@ -30,7 +30,7 @@ pub type Request = HttpRequest<()>;
pub type Response = HttpResponse<()>; pub type Response = HttpResponse<()>;
/// Server error response type. /// Server error response type.
pub type ErrorResponse = HttpResponse<Option<String>>; pub type ErrorResponse = HttpResponse<Vec<u8>>;
fn create_parts<T>(request: &HttpRequest<T>) -> Result<Builder> { fn create_parts<T>(request: &HttpRequest<T>) -> Result<Builder> {
if request.method() != http::Method::GET { if request.method() != http::Method::GET {
@ -253,9 +253,7 @@ impl<S: Read + Write, C: Callback> HandshakeRole for ServerHandshake<S, C> {
let mut output = vec![]; let mut output = vec![];
write_response(&mut output, resp)?; write_response(&mut output, resp)?;
if let Some(body) = resp.body() { output.extend(resp.body());
output.extend_from_slice(body.as_bytes());
}
ProcessingResult::Continue(HandshakeMachine::start_write(stream, output)) ProcessingResult::Continue(HandshakeMachine::start_write(stream, output))
} }
@ -267,8 +265,7 @@ impl<S: Read + Write, C: Callback> HandshakeRole for ServerHandshake<S, C> {
debug!("Server handshake failed."); debug!("Server handshake failed.");
let (parts, body) = err.into_parts(); let (parts, body) = err.into_parts();
let body = body.map(|b| b.as_bytes().to_vec()); return Err(Error::Http(http::Response::from_parts(parts, Some(body))));
return Err(Error::Http(http::Response::from_parts(parts, body)));
} 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);

Loading…
Cancel
Save