Skip to content

Commit

Permalink
Add ETag to failed conditional GETs in LocalBlobStore
Browse files Browse the repository at this point in the history
  • Loading branch information
gaul committed Sep 5, 2024
1 parent d62322c commit 9b48d04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions blobstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.concurrent.ExecutorService;

import jakarta.annotation.Resource;
import jakarta.ws.rs.core.Response.Status;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

Expand Down Expand Up @@ -640,29 +641,39 @@ public Blob getBlob(String containerName, String key, GetOptions options) {
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);
Expand Down

0 comments on commit 9b48d04

Please sign in to comment.