Skip to content

Commit

Permalink
Support redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dubzer committed Oct 12, 2023
1 parent 6e2f76a commit cc8f6c6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub async fn handle(mut req: Request<Body>, origin: HeaderValue) -> Result<Respo
.ok_or_else(|| HandlerError::new_with_origin("sowwy, you might have fowgotten host in your destination", StatusCode::BAD_REQUEST, origin.clone()))?;


req.headers_mut().insert("Host", HeaderValue::from_str(destination_host.as_str()).unwrap());
let cors_host = req.headers_mut()
.insert("Host", HeaderValue::from_str(destination_host.as_str()).unwrap())
.ok_or_else(|| HandlerError::new_with_origin("sowwy, you might have fowgotten host headew", StatusCode::BAD_REQUEST, origin.clone()))?;

*req.uri_mut() = destination_uri;

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

if let Some(location) = parts.headers.get_mut("Location") {
*location = HeaderValue::from_str(format!("https://{}/{}", cors_host.to_str()?, location.to_str()?).as_str())?;
}

return Ok(Response::from_parts(parts, body));
}

Expand Down

0 comments on commit cc8f6c6

Please sign in to comment.