implement x-amz-website-redirect-location header #869

Open
opened 2024-08-28 13:14:19 +00:00 by yuka · 0 comments
Contributor

the quick and dirty patch I came up with is below

todo:

  • make it work for types of requests other than put/get
  • check the semantics for copying/renaming objects to match AWS
diff --git a/src/api/s3/get.rs b/src/api/s3/get.rs
index f5d3cf11..351be6c1 100644
--- a/src/api/s3/get.rs
+++ b/src/api/s3/get.rs
@@ -329,6 +329,19 @@ pub async fn handle_get_without_ctx(
 
 	let checksum_mode = checksum_mode(&req);
 
+	if let Some(redirect_hdr) = headers
+		.headers
+		.iter()
+		.find(|(k, _)| k == "x-amz-website-redirect-location")
+		.map(|(_, v)| v)
+	{
+            return Ok(Response::builder()
+                .status(StatusCode::FOUND)
+                .header("Location", redirect_hdr)
+                .body(empty_body())
+                .unwrap());
+	}
+
 	match (part_number, parse_range_header(req, last_v_meta.size)?) {
 		(Some(_), Some(_)) => Err(Error::bad_request(
 			"Cannot specify both partNumber and Range header",
diff --git a/src/api/s3/put.rs b/src/api/s3/put.rs
index 1e3b1b44..956db2e0 100644
--- a/src/api/s3/put.rs
+++ b/src/api/s3/put.rs
@@ -618,9 +618,11 @@ pub(crate) fn get_headers(headers: &HeaderMap<HeaderValue>) -> Result<HeaderList
 		}
 	}
 
-	// Preserve x-amz-meta- headers
+	// Preserve x-amz-meta- and x-amz-website-redirect-location headers
 	for (name, value) in headers.iter() {
-		if name.as_str().starts_with("x-amz-meta-") {
+		if name.as_str().starts_with("x-amz-meta-")
+			|| name.as_str() == "x-amz-website-redirect-location"
+		{
 			ret.push((
 				name.to_string(),
 				std::str::from_utf8(value.as_bytes())?.to_string(),
the quick and dirty patch I came up with is below todo: - make it work for types of requests other than put/get - check the semantics for copying/renaming objects to match AWS ``` diff --git a/src/api/s3/get.rs b/src/api/s3/get.rs index f5d3cf11..351be6c1 100644 --- a/src/api/s3/get.rs +++ b/src/api/s3/get.rs @@ -329,6 +329,19 @@ pub async fn handle_get_without_ctx( let checksum_mode = checksum_mode(&req); + if let Some(redirect_hdr) = headers + .headers + .iter() + .find(|(k, _)| k == "x-amz-website-redirect-location") + .map(|(_, v)| v) + { + return Ok(Response::builder() + .status(StatusCode::FOUND) + .header("Location", redirect_hdr) + .body(empty_body()) + .unwrap()); + } + match (part_number, parse_range_header(req, last_v_meta.size)?) { (Some(_), Some(_)) => Err(Error::bad_request( "Cannot specify both partNumber and Range header", diff --git a/src/api/s3/put.rs b/src/api/s3/put.rs index 1e3b1b44..956db2e0 100644 --- a/src/api/s3/put.rs +++ b/src/api/s3/put.rs @@ -618,9 +618,11 @@ pub(crate) fn get_headers(headers: &HeaderMap<HeaderValue>) -> Result<HeaderList } } - // Preserve x-amz-meta- headers + // Preserve x-amz-meta- and x-amz-website-redirect-location headers for (name, value) in headers.iter() { - if name.as_str().starts_with("x-amz-meta-") { + if name.as_str().starts_with("x-amz-meta-") + || name.as_str() == "x-amz-website-redirect-location" + { ret.push(( name.to_string(), std::str::from_utf8(value.as_bytes())?.to_string(), ```
quentin added the
kind
wrong-behavior
scope
s3-api
action
triage-required
labels 2024-08-29 09:37:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/garage#869
No description provided.