|
42 | 42 | import java.util.concurrent.ExecutorService; |
43 | 43 |
|
44 | 44 | import jakarta.annotation.Resource; |
| 45 | +import jakarta.ws.rs.core.Response.Status; |
45 | 46 | import jakarta.inject.Inject; |
46 | 47 | import jakarta.inject.Singleton; |
47 | 48 |
|
@@ -640,29 +641,39 @@ public Blob getBlob(String containerName, String key, GetOptions options) { |
640 | 641 | if (eTag != null) { |
641 | 642 | eTag = maybeQuoteETag(eTag); |
642 | 643 | 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 | + } |
645 | 648 | } |
646 | 649 | 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 | + } |
649 | 654 | } |
650 | 655 | } |
651 | 656 | if (options.getIfModifiedSince() != null) { |
652 | 657 | Date modifiedSince = options.getIfModifiedSince(); |
653 | 658 | 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 | + } |
655 | 663 | 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()); |
657 | 665 | } |
658 | 666 |
|
659 | 667 | } |
660 | 668 | if (options.getIfUnmodifiedSince() != null) { |
661 | 669 | Date unmodifiedSince = options.getIfUnmodifiedSince(); |
662 | 670 | 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 | + } |
664 | 675 | 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()); |
666 | 677 | } |
667 | 678 | } |
668 | 679 | blob = copyBlob(blob); |
|
0 commit comments