Refactor Responder implementation for RumaResponse

next
Jonas Platte 2021-04-23 18:16:24 +02:00 committed by Timo Kösters
parent 23f81bfaf7
commit 7067d7acae
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
1 changed files with 25 additions and 27 deletions

View File

@ -314,17 +314,18 @@ where
'o: 'r, 'o: 'r,
{ {
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'o> { fn respond_to(self, _: &'r Request<'_>) -> response::Result<'o> {
let http_response: Result<http::Response<_>, _> = self.0.try_into_http_response(); let http_response = self
match http_response { .0
Ok(http_response) => { .try_into_http_response()
.map_err(|_| Status::InternalServerError)?;
let mut response = rocket::response::Response::build(); let mut response = rocket::response::Response::build();
let status = http_response.status(); let status = http_response.status();
response.raw_status(status.into(), ""); response.raw_status(status.into(), "");
for header in http_response.headers() { for header in http_response.headers() {
response response.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
} }
let http_body = http_response.into_body(); let http_body = http_response.into_body();
@ -343,7 +344,4 @@ where
response.raw_header("Access-Control-Max-Age", "86400"); response.raw_header("Access-Control-Max-Age", "86400");
response.ok() response.ok()
} }
Err(_) => Err(Status::InternalServerError),
}
}
} }