1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 16:10:42 +00:00

add headers to the response (#27)

This commit is contained in:
Dominic 2021-01-14 18:37:51 +01:00
parent 3600a115d0
commit 44f3c9fe84
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
9 changed files with 48 additions and 12 deletions

View file

@ -81,10 +81,21 @@ pub trait DrawResourceRoutes {
fn remove<Handler: ResourceRemove>(&mut self);
}
#[allow(deprecated)]
fn response_from(res: Response, state: &State) -> gotham::hyper::Response<Body> {
let mut r = create_empty_response(state, res.status);
let headers = r.headers_mut();
if let Some(mime) = res.mime {
r.headers_mut().insert(CONTENT_TYPE, mime.as_ref().parse().unwrap());
headers.insert(CONTENT_TYPE, mime.as_ref().parse().unwrap());
}
let mut last_name = None;
for (name, value) in res.headers {
if name.is_some() {
last_name = name;
}
// this unwrap is safe: the first item will always be Some
let name = last_name.clone().unwrap();
headers.insert(name, value);
}
let method = Method::borrow_from(state);