Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 9b48d04

Browse files
committed
Add ETag to failed conditional GETs in LocalBlobStore
1 parent d62322c commit 9b48d04

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

blobstore/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<artifactId>jclouds-core</artifactId>
4343
<version>${project.version}</version>
4444
</dependency>
45+
<dependency>
46+
<groupId>jakarta.ws.rs</groupId>
47+
<artifactId>jakarta.ws.rs-api</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>${project.groupId}</groupId>
4751
<artifactId>jclouds-core</artifactId>

blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.ExecutorService;
4343

4444
import jakarta.annotation.Resource;
45+
import jakarta.ws.rs.core.Response.Status;
4546
import jakarta.inject.Inject;
4647
import jakarta.inject.Singleton;
4748

@@ -640,29 +641,39 @@ public Blob getBlob(String containerName, String key, GetOptions options) {
640641
if (eTag != null) {
641642
eTag = maybeQuoteETag(eTag);
642643
if (options.getIfMatch() != null) {
643-
if (!eTag.equals(maybeQuoteETag(options.getIfMatch())))
644-
throw returnResponseException(412);
644+
if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) {
645+
HttpResponse response = HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode()).addHeader(HttpHeaders.ETAG, eTag).build();
646+
throw new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub").build()), response);
647+
}
645648
}
646649
if (options.getIfNoneMatch() != null) {
647-
if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch())))
648-
throw returnResponseException(304);
650+
if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) {
651+
HttpResponse response = HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode()).addHeader(HttpHeaders.ETAG, eTag).build();
652+
throw new HttpResponseException(new HttpCommand(HttpRequest.builder().method("GET").endpoint("http://stub").build()), response);
653+
}
649654
}
650655
}
651656
if (options.getIfModifiedSince() != null) {
652657
Date modifiedSince = options.getIfModifiedSince();
653658
if (blob.getMetadata().getLastModified().before(modifiedSince)) {
654-
HttpResponse response = HttpResponse.builder().statusCode(304).build();
659+
HttpResponse.Builder response = HttpResponse.builder().statusCode(Status.NOT_MODIFIED.getStatusCode());
660+
if (eTag != null) {
661+
response.addHeader(HttpHeaders.ETAG, eTag);
662+
}
655663
throw new HttpResponseException(String.format("%1$s is before %2$s", blob
656-
.getMetadata().getLastModified(), modifiedSince), null, response);
664+
.getMetadata().getLastModified(), modifiedSince), null, response.build());
657665
}
658666

659667
}
660668
if (options.getIfUnmodifiedSince() != null) {
661669
Date unmodifiedSince = options.getIfUnmodifiedSince();
662670
if (blob.getMetadata().getLastModified().after(unmodifiedSince)) {
663-
HttpResponse response = HttpResponse.builder().statusCode(412).build();
671+
HttpResponse.Builder response = HttpResponse.builder().statusCode(Status.PRECONDITION_FAILED.getStatusCode());
672+
if (eTag != null) {
673+
response.addHeader(HttpHeaders.ETAG, eTag);
674+
}
664675
throw new HttpResponseException(String.format("%1$s is after %2$s", blob
665-
.getMetadata().getLastModified(), unmodifiedSince), null, response);
676+
.getMetadata().getLastModified(), unmodifiedSince), null, response.build());
666677
}
667678
}
668679
blob = copyBlob(blob);

0 commit comments

Comments
 (0)