This is an automated email from the ASF dual-hosted git repository.

gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b48d04502 Add ETag to failed conditional GETs in LocalBlobStore
9b48d04502 is described below

commit 9b48d045023382654706b16cf588565f316aaa4b
Author: Andrew Gaul <[email protected]>
AuthorDate: Wed Sep 4 23:42:25 2024 +0200

    Add ETag to failed conditional GETs in LocalBlobStore
---
 blobstore/pom.xml                                  |  4 ++++
 .../jclouds/blobstore/config/LocalBlobStore.java   | 27 +++++++++++++++-------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/blobstore/pom.xml b/blobstore/pom.xml
index 55d2196e26..0dc537ff68 100644
--- a/blobstore/pom.xml
+++ b/blobstore/pom.xml
@@ -42,6 +42,10 @@
       <artifactId>jclouds-core</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>jakarta.ws.rs</groupId>
+      <artifactId>jakarta.ws.rs-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>jclouds-core</artifactId>
diff --git 
a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java 
b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
index c5ed0effbd..b83a7d022d 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
@@ -42,6 +42,7 @@ import java.util.UUID;
 import java.util.concurrent.ExecutorService;
 
 import jakarta.annotation.Resource;
+import jakarta.ws.rs.core.Response.Status;
 import jakarta.inject.Inject;
 import jakarta.inject.Singleton;
 
@@ -640,29 +641,39 @@ public final class LocalBlobStore implements BlobStore {
          if (eTag != null) {
             eTag = maybeQuoteETag(eTag);
             if (options.getIfMatch() != null) {
-               if (!eTag.equals(maybeQuoteETag(options.getIfMatch())))
-                  throw returnResponseException(412);
+               if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) {
+                  HttpResponse response = 
HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode()).addHeader(HttpHeaders.ETAG,
 eTag).build();
+                  throw new HttpResponseException(new 
HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub";).build()),
 response);
+               }
             }
             if (options.getIfNoneMatch() != null) {
-               if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch())))
-                  throw returnResponseException(304);
+               if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) {
+                  HttpResponse response = 
HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode()).addHeader(HttpHeaders.ETAG,
 eTag).build();
+                  throw new HttpResponseException(new 
HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub";).build()),
 response);
+               }
             }
          }
          if (options.getIfModifiedSince() != null) {
             Date modifiedSince = options.getIfModifiedSince();
             if (blob.getMetadata().getLastModified().before(modifiedSince)) {
-               HttpResponse response = 
HttpResponse.builder().statusCode(304).build();
+               HttpResponse.Builder response = 
HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode());
+               if (eTag != null) {
+                  response.addHeader(HttpHeaders.ETAG, eTag);
+               }
                throw new HttpResponseException(String.format("%1$s is before 
%2$s", blob
-                     .getMetadata().getLastModified(), modifiedSince), null, 
response);
+                     .getMetadata().getLastModified(), modifiedSince), null, 
response.build());
             }
 
          }
          if (options.getIfUnmodifiedSince() != null) {
             Date unmodifiedSince = options.getIfUnmodifiedSince();
             if (blob.getMetadata().getLastModified().after(unmodifiedSince)) {
-               HttpResponse response = 
HttpResponse.builder().statusCode(412).build();
+               HttpResponse.Builder response = 
HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode());
+               if (eTag != null) {
+                  response.addHeader(HttpHeaders.ETAG, eTag);
+               }
                throw new HttpResponseException(String.format("%1$s is after 
%2$s", blob
-                     .getMetadata().getLastModified(), unmodifiedSince), null, 
response);
+                     .getMetadata().getLastModified(), unmodifiedSince), null, 
response.build());
             }
          }
          blob = copyBlob(blob);

Reply via email to