1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-18 20:00:51 +01:00

Refactor Responder implementation for RumaResponse

This commit is contained in:
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

View file

@ -314,36 +314,34 @@ 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()
let mut response = rocket::response::Response::build(); .map_err(|_| Status::InternalServerError)?;
let status = http_response.status(); let mut response = rocket::response::Response::build();
response.raw_status(status.into(), "");
for header in http_response.headers() { let status = http_response.status();
response response.raw_status(status.into(), "");
.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
}
let http_body = http_response.into_body(); for header in http_response.headers() {
response.raw_header(header.0.to_string(), header.1.to_str().unwrap().to_owned());
response.sized_body(http_body.len(), Cursor::new(http_body));
response.raw_header("Access-Control-Allow-Origin", "*");
response.raw_header(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS",
);
response.raw_header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization",
);
response.raw_header("Access-Control-Max-Age", "86400");
response.ok()
}
Err(_) => Err(Status::InternalServerError),
} }
let http_body = http_response.into_body();
response.sized_body(http_body.len(), Cursor::new(http_body));
response.raw_header("Access-Control-Allow-Origin", "*");
response.raw_header(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS",
);
response.raw_header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization",
);
response.raw_header("Access-Control-Max-Age", "86400");
response.ok()
} }
} }