Make try_into_http_response
more safe
Remove `expect`s and `unwrap`s from `try_into_http_response`.
This commit is contained in:
parent
e2eb92b8ed
commit
b610a725e8
@ -78,14 +78,11 @@ impl Response {
|
|||||||
let mut resp_builder = #http::Response::builder()
|
let mut resp_builder = #http::Response::builder()
|
||||||
.header(#http::header::CONTENT_TYPE, "application/json");
|
.header(#http::header::CONTENT_TYPE, "application/json");
|
||||||
|
|
||||||
let mut headers = resp_builder
|
if let Some(mut headers) = resp_builder.headers_mut() {
|
||||||
.headers_mut()
|
|
||||||
.expect("`http::ResponseBuilder` is in unusable state");
|
|
||||||
#(#serialize_response_headers)*
|
#(#serialize_response_headers)*
|
||||||
|
}
|
||||||
|
|
||||||
// This cannot fail because we parse each header value checking for errors as
|
::std::result::Result::Ok(resp_builder.body(#body)?)
|
||||||
// each value is inserted and we only allow keys from the `http::header` module.
|
|
||||||
::std::result::Result::Ok(resp_builder.body(#body).unwrap())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user