Refactor Responder implementation for RumaResponse
This commit is contained in:
		
							parent
							
								
									23f81bfaf7
								
							
						
					
					
						commit
						7067d7acae
					
				
					 1 changed files with 25 additions and 27 deletions
				
			
		|  | @ -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() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue