From bf27a3ec9844cf86f2a7ca67b94e7fb8db3873df Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 19 Feb 2025 17:04:10 +0100 Subject: web: implement x-amz-website-redirect-location --- src/web/web_server.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/web') 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()) } -- cgit v1.2.3