Make try_into_http_response more safe

Remove `expect`s and `unwrap`s from `try_into_http_response`.
This commit is contained in:
gnieto 2021-05-08 20:22:06 +02:00 committed by GitHub
parent e2eb92b8ed
commit b610a725e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,14 +78,11 @@ impl Response {
let mut resp_builder = #http::Response::builder()
.header(#http::header::CONTENT_TYPE, "application/json");
let mut headers = resp_builder
.headers_mut()
.expect("`http::ResponseBuilder` is in unusable state");
#(#serialize_response_headers)*
if let Some(mut headers) = resp_builder.headers_mut() {
#(#serialize_response_headers)*
}
// This cannot fail because we parse each header value checking for errors as
// each value is inserted and we only allow keys from the `http::header` module.
::std::result::Result::Ok(resp_builder.body(#body).unwrap())
::std::result::Result::Ok(resp_builder.body(#body)?)
}
}
}