Repository: jclouds Updated Branches: refs/heads/master 8d87bfc61 -> 25f4807df
Tolerate missing or extra quotes in ETags References andrewgaul/s3proxy#77. Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/25f4807d Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/25f4807d Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/25f4807d Branch: refs/heads/master Commit: 25f4807df868cff9a9da599009adc0091f7bb52b Parents: 8d87bfc Author: Andrew Gaul <[email protected]> Authored: Thu Nov 19 17:40:48 2015 -0800 Committer: Andrew Gaul <[email protected]> Committed: Thu Nov 19 17:40:48 2015 -0800 ---------------------------------------------------------------------- .../org/jclouds/blobstore/config/LocalBlobStore.java | 11 +++++++++-- .../main/java/org/jclouds/http/options/GetOptions.java | 10 ++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/25f4807d/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java ---------------------------------------------------------------------- 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 8d799c6..96edd2e 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -630,11 +630,11 @@ public final class LocalBlobStore implements BlobStore { if (options != null) { if (options.getIfMatch() != null) { - if (!blob.getMetadata().getETag().equals(options.getIfMatch())) + if (!maybeQuoteETag(blob.getMetadata().getETag()).equals(options.getIfMatch())) throw returnResponseException(412); } if (options.getIfNoneMatch() != null) { - if (blob.getMetadata().getETag().equals(options.getIfNoneMatch())) + if (maybeQuoteETag(blob.getMetadata().getETag()).equals(options.getIfNoneMatch())) throw returnResponseException(304); } if (options.getIfModifiedSince() != null) { @@ -857,4 +857,11 @@ public final class LocalBlobStore implements BlobStore { public int getMaximumNumberOfParts() { return Integer.MAX_VALUE; } + + private static String maybeQuoteETag(String eTag) { + if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) { + eTag = "\"" + eTag + "\""; + } + return eTag; + } } http://git-wip-us.apache.org/repos/asf/jclouds/blob/25f4807d/core/src/main/java/org/jclouds/http/options/GetOptions.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/http/options/GetOptions.java b/core/src/main/java/org/jclouds/http/options/GetOptions.java index 278a40a..9844aed 100644 --- a/core/src/main/java/org/jclouds/http/options/GetOptions.java +++ b/core/src/main/java/org/jclouds/http/options/GetOptions.java @@ -161,7 +161,7 @@ public class GetOptions extends BaseHttpRequestOptions { public GetOptions ifETagMatches(String eTag) { checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()"); checkArgument(getIfModifiedSince() == null, "ifModifiedSince() is not compatible with ifETagMatches()"); - this.headers.put(IF_MATCH, String.format("\"%1$s\"", checkNotNull(eTag, "eTag"))); + this.headers.put(IF_MATCH, maybeQuoteETag(checkNotNull(eTag, "eTag"))); return this; } @@ -188,7 +188,7 @@ public class GetOptions extends BaseHttpRequestOptions { public GetOptions ifETagDoesntMatch(String eTag) { checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()"); checkArgument(getIfUnmodifiedSince() == null, "ifUnmodifiedSince() is not compatible with ifETagDoesntMatch()"); - this.headers.put(IF_NONE_MATCH, String.format("\"%1$s\"", checkNotNull(eTag, "ifETagDoesntMatch"))); + this.headers.put(IF_NONE_MATCH, maybeQuoteETag(checkNotNull(eTag, "ifETagDoesntMatch"))); return this; } @@ -299,4 +299,10 @@ public class GetOptions extends BaseHttpRequestOptions { + ", payload=" + payload + ", pathSuffix=" + pathSuffix + ", ranges=" + ranges + "]"; } + private static String maybeQuoteETag(String eTag) { + if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) { + eTag = "\"" + eTag + "\""; + } + return eTag; + } }
