Skip to content

Commit cc8f6c6

Browse files
committed
Support redirects
1 parent 6e2f76a commit cc8f6c6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/handlers.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub async fn handle(mut req: Request<Body>, origin: HeaderValue) -> Result<Respo
4545
.ok_or_else(|| HandlerError::new_with_origin("sowwy, you might have fowgotten host in your destination", StatusCode::BAD_REQUEST, origin.clone()))?;
4646

4747

48-
req.headers_mut().insert("Host", HeaderValue::from_str(destination_host.as_str()).unwrap());
48+
let cors_host = req.headers_mut()
49+
.insert("Host", HeaderValue::from_str(destination_host.as_str()).unwrap())
50+
.ok_or_else(|| HandlerError::new_with_origin("sowwy, you might have fowgotten host headew", StatusCode::BAD_REQUEST, origin.clone()))?;
51+
4952
*req.uri_mut() = destination_uri;
5053

5154
let client_response = GLOBAL_CLIENT.request(req).await
@@ -55,6 +58,10 @@ pub async fn handle(mut req: Request<Body>, origin: HeaderValue) -> Result<Respo
5558
let (mut parts, body) = client_response.into_parts();
5659
parts.headers.extend(get_default_cors(origin.clone()));
5760

61+
if let Some(location) = parts.headers.get_mut("Location") {
62+
*location = HeaderValue::from_str(format!("https://{}/{}", cors_host.to_str()?, location.to_str()?).as_str())?;
63+
}
64+
5865
return Ok(Response::from_parts(parts, body));
5966
}
6067

0 commit comments

Comments
 (0)