diff options
author | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-19 17:04:10 +0100 |
---|---|---|
committer | Alex Auvolat <lx@deuxfleurs.fr> | 2025-02-19 17:04:10 +0100 |
commit | bf27a3ec9844cf86f2a7ca67b94e7fb8db3873df (patch) | |
tree | b6f1f1552f38de61ca8309942e5e2dd682a6e876 /src/web | |
parent | f64ec6e542c73a4eaaf1962330c7bfe4d7c47461 (diff) | |
download | garage-bf27a3ec9844cf86f2a7ca67b94e7fb8db3873df.tar.gz garage-bf27a3ec9844cf86f2a7ca67b94e7fb8db3873df.zip |
web: implement x-amz-website-redirect-location
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/web_server.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/web/web_server.rs b/src/web/web_server.rs index 34ba834c..242f7801 100644 --- a/src/web/web_server.rs +++ b/src/web/web_server.rs @@ -7,7 +7,7 @@ use tokio::sync::watch; use hyper::{ body::Incoming as IncomingBody, - header::{HeaderValue, HOST}, + header::{HeaderValue, HOST, LOCATION}, Method, Request, Response, StatusCode, }; @@ -29,6 +29,7 @@ use garage_api_s3::error::{ CommonErrorDerivative, Error as ApiError, OkOrBadRequest, OkOrInternalError, }; use garage_api_s3::get::{handle_get_without_ctx, handle_head_without_ctx}; +use garage_api_s3::website::X_AMZ_WEBSITE_REDIRECT_LOCATION; use garage_model::garage::Garage; @@ -294,7 +295,15 @@ impl WebServer { { Ok(Response::builder() .status(StatusCode::FOUND) - .header("Location", url) + .header(LOCATION, url) + .body(empty_body()) + .unwrap()) + } + (Ok(ret), _) if ret.headers().contains_key(X_AMZ_WEBSITE_REDIRECT_LOCATION) => { + let redirect_location = ret.headers().get(X_AMZ_WEBSITE_REDIRECT_LOCATION).unwrap(); + Ok(Response::builder() + .status(StatusCode::MOVED_PERMANENTLY) + .header(LOCATION, redirect_location) .body(empty_body()) .unwrap()) } |