Tolerate missing or extra quotes in ETags

References andrewgaul/s3proxy#77.
This commit is contained in:
Andrew Gaul 2015-11-19 17:40:48 -08:00
parent 8d87bfc61b
commit 25f4807df8
2 changed files with 17 additions and 4 deletions

View File

@ -630,11 +630,11 @@ public final class LocalBlobStore implements BlobStore {
if (options != null) { if (options != null) {
if (options.getIfMatch() != null) { if (options.getIfMatch() != null) {
if (!blob.getMetadata().getETag().equals(options.getIfMatch())) if (!maybeQuoteETag(blob.getMetadata().getETag()).equals(options.getIfMatch()))
throw returnResponseException(412); throw returnResponseException(412);
} }
if (options.getIfNoneMatch() != null) { if (options.getIfNoneMatch() != null) {
if (blob.getMetadata().getETag().equals(options.getIfNoneMatch())) if (maybeQuoteETag(blob.getMetadata().getETag()).equals(options.getIfNoneMatch()))
throw returnResponseException(304); throw returnResponseException(304);
} }
if (options.getIfModifiedSince() != null) { if (options.getIfModifiedSince() != null) {
@ -857,4 +857,11 @@ public final class LocalBlobStore implements BlobStore {
public int getMaximumNumberOfParts() { public int getMaximumNumberOfParts() {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }
private static String maybeQuoteETag(String eTag) {
if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) {
eTag = "\"" + eTag + "\"";
}
return eTag;
}
} }

View File

@ -161,7 +161,7 @@ public class GetOptions extends BaseHttpRequestOptions {
public GetOptions ifETagMatches(String eTag) { public GetOptions ifETagMatches(String eTag) {
checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()"); checkArgument(getIfNoneMatch() == null, "ifETagDoesntMatch() is not compatible with ifETagMatches()");
checkArgument(getIfModifiedSince() == null, "ifModifiedSince() 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; return this;
} }
@ -188,7 +188,7 @@ public class GetOptions extends BaseHttpRequestOptions {
public GetOptions ifETagDoesntMatch(String eTag) { public GetOptions ifETagDoesntMatch(String eTag) {
checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()"); checkArgument(getIfMatch() == null, "ifETagMatches() is not compatible with ifETagDoesntMatch()");
checkArgument(getIfUnmodifiedSince() == null, "ifUnmodifiedSince() 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; return this;
} }
@ -299,4 +299,10 @@ public class GetOptions extends BaseHttpRequestOptions {
+ ", payload=" + payload + ", pathSuffix=" + pathSuffix + ", ranges=" + ranges + "]"; + ", payload=" + payload + ", pathSuffix=" + pathSuffix + ", ranges=" + ranges + "]";
} }
private static String maybeQuoteETag(String eTag) {
if (!eTag.startsWith("\"") && !eTag.endsWith("\"")) {
eTag = "\"" + eTag + "\"";
}
return eTag;
}
} }