Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Commit

Permalink
Tolerate missing or extra quotes in ETags
Browse files Browse the repository at this point in the history
References gaul/s3proxy#77.
  • Loading branch information
gaul committed Nov 20, 2015
1 parent 8d87bfc commit 25f4807
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Expand Up @@ -630,11 +630,11 @@ public Blob getBlob(String containerName, String key, GetOptions options) {

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) {
Expand Down Expand Up @@ -857,4 +857,11 @@ public long getMaximumMultipartPartSize() {
public int getMaximumNumberOfParts() {
return Integer.MAX_VALUE;
}

private static String maybeQuoteETag(String eTag) {
if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) {
eTag = "\"" + eTag + "\"";
}
return eTag;
}
}
10 changes: 8 additions & 2 deletions core/src/main/java/org/jclouds/http/options/GetOptions.java
Expand Up @@ -161,7 +161,7 @@ public String getIfUnmodifiedSince() {
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;
}

Expand All @@ -188,7 +188,7 @@ public String getIfMatch() {
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;
}

Expand Down Expand Up @@ -299,4 +299,10 @@ public String toString() {
+ ", payload=" + payload + ", pathSuffix=" + pathSuffix + ", ranges=" + ranges + "]";
}

private static String maybeQuoteETag(String eTag) {
if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) {
eTag = "\"" + eTag + "\"";
}
return eTag;
}
}

0 comments on commit 25f4807

Please sign in to comment.