From cb443b780b116380328b8f846075919f322c0ca0 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 5 Sep 2024 00:32:33 +0200 Subject: [PATCH] Add ETag to failed conditional GETs Found via s3-tests. References apache/jclouds#209. --- src/main/java/org/gaul/s3proxy/S3ProxyHandlerJetty.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandlerJetty.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandlerJetty.java index 62cd01f7..9fea5da3 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandlerJetty.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandlerJetty.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import com.google.common.collect.ImmutableMap; +import com.google.common.net.HttpHeaders; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -94,6 +95,12 @@ public void handle(String target, Request baseRequest, hre.getMessage()); return; } + + String eTag = hr.getFirstHeaderOrNull(HttpHeaders.ETAG); + if (eTag != null) { + response.setHeader(HttpHeaders.ETAG, eTag); + } + int status = hr.getStatusCode(); switch (status) { case 412: @@ -111,7 +118,7 @@ public void handle(String target, Request baseRequest, break; default: logger.debug("HttpResponseException:", hre); - response.sendError(status, hre.getContent()); + response.setStatus(status); break; } baseRequest.setHandled(true);