mirror of https://github.com/apache/jclouds.git
JCLOUDS-948: S3 Cache-Control support
Deprecate older S3-specific Cache-Control mechanism.
This commit is contained in:
parent
82ad05e98e
commit
f292408af4
|
@ -54,8 +54,8 @@ public class BindObjectMetadataToRequest implements Binder {
|
|||
request = metadataPrefixer.bindToRequest(request, md.getUserMetadata());
|
||||
|
||||
Builder<String, String> headers = ImmutableMultimap.builder();
|
||||
if (md.getCacheControl() != null) {
|
||||
headers.put(HttpHeaders.CACHE_CONTROL, md.getCacheControl());
|
||||
if (md.getContentMetadata().getCacheControl() != null) {
|
||||
headers.put(HttpHeaders.CACHE_CONTROL, md.getContentMetadata().getCacheControl());
|
||||
}
|
||||
|
||||
if (md.getContentMetadata().getContentDisposition() != null) {
|
||||
|
|
|
@ -27,8 +27,6 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.s3.domain.S3Object;
|
||||
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
@Singleton
|
||||
public class BindS3ObjectMetadataToRequest implements Binder {
|
||||
protected final BindMapToHeadersWithPrefix metadataPrefixer;
|
||||
|
@ -53,10 +51,6 @@ public class BindS3ObjectMetadataToRequest implements Binder {
|
|||
|
||||
request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata());
|
||||
|
||||
if (s3Object.getMetadata().getCacheControl() != null) {
|
||||
request = (R) request.toBuilder()
|
||||
.replaceHeader(HttpHeaders.CACHE_CONTROL, s3Object.getMetadata().getCacheControl()).build();
|
||||
}
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,6 +278,11 @@ public class S3BlobStore extends BaseBlobStore {
|
|||
|
||||
Optional<ContentMetadata> contentMetadata = options.getContentMetadata();
|
||||
if (contentMetadata.isPresent()) {
|
||||
String cacheControl = contentMetadata.get().getCacheControl();
|
||||
if (cacheControl != null) {
|
||||
s3Options.cacheControl(cacheControl);
|
||||
}
|
||||
|
||||
String contentDisposition = contentMetadata.get().getContentDisposition();
|
||||
if (contentDisposition != null) {
|
||||
s3Options.contentDisposition(contentDisposition);
|
||||
|
|
|
@ -59,7 +59,10 @@ public interface MutableObjectMetadata extends ObjectMetadata {
|
|||
* Can be used to specify caching behavior along the request/reply chain.
|
||||
*
|
||||
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html?sec14.9.
|
||||
*
|
||||
* @deprecated call getContentMetadata().setCacheControl(String) instead
|
||||
*/
|
||||
@Deprecated
|
||||
void setCacheControl(String cacheControl);
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,7 +63,10 @@ public interface ObjectMetadata extends Comparable<ObjectMetadata> {
|
|||
* Can be used to specify caching behavior along the request/reply chain.
|
||||
*
|
||||
* @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html?sec14.9.
|
||||
*
|
||||
* @deprecated call getContentMetadata().getCacheControl() instead
|
||||
*/
|
||||
@Deprecated
|
||||
String getCacheControl();
|
||||
|
||||
Date getLastModified();
|
||||
|
|
|
@ -42,7 +42,6 @@ public class ObjectMetadataBuilder {
|
|||
private String bucket;
|
||||
private URI uri;
|
||||
private StorageClass storageClass = StorageClass.STANDARD;
|
||||
private String cacheControl;
|
||||
private Date lastModified;
|
||||
private String eTag;
|
||||
private CanonicalUser owner;
|
||||
|
@ -84,7 +83,7 @@ public class ObjectMetadataBuilder {
|
|||
}
|
||||
|
||||
public ObjectMetadataBuilder cacheControl(String cacheControl) {
|
||||
this.cacheControl = cacheControl;
|
||||
contentMetadataBuilder.cacheControl(cacheControl);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -130,7 +129,6 @@ public class ObjectMetadataBuilder {
|
|||
public ObjectMetadata build() {
|
||||
MutableObjectMetadataImpl toReturn = new MutableObjectMetadataImpl();
|
||||
toReturn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(contentMetadataBuilder.build()));
|
||||
toReturn.setCacheControl(cacheControl);
|
||||
toReturn.setKey(key);
|
||||
toReturn.setBucket(bucket);
|
||||
toReturn.setUri(uri);
|
||||
|
|
|
@ -108,11 +108,12 @@ public class MutableObjectMetadataImpl implements MutableObjectMetadata {
|
|||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
* @deprecated call getContentMetadata().getCacheControl() instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getCacheControl() {
|
||||
return cacheControl;
|
||||
return contentMetadata.getCacheControl();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,11 +149,12 @@ public class MutableObjectMetadataImpl implements MutableObjectMetadata {
|
|||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
* @deprecated call getContentMetadata().setCacheControl(String) instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public void setCacheControl(String cacheControl) {
|
||||
this.cacheControl = cacheControl;
|
||||
contentMetadata.setCacheControl(cacheControl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,6 +72,7 @@ import com.google.common.net.HttpHeaders;
|
|||
public class CopyObjectOptions extends BaseHttpRequestOptions {
|
||||
private static final DateService dateService = new SimpleDateFormatDateService();
|
||||
public static final CopyObjectOptions NONE = new CopyObjectOptions();
|
||||
private String cacheControl;
|
||||
private String contentDisposition;
|
||||
private String contentEncoding;
|
||||
private String contentLanguage;
|
||||
|
@ -255,6 +256,10 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
returnVal.put(entry.getKey().replace(DEFAULT_AMAZON_HEADERTAG, headerTag), entry.getValue());
|
||||
}
|
||||
boolean replace = false;
|
||||
if (cacheControl != null) {
|
||||
returnVal.put(HttpHeaders.CACHE_CONTROL, cacheControl);
|
||||
replace = true;
|
||||
}
|
||||
if (contentDisposition != null) {
|
||||
returnVal.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
|
||||
replace = true;
|
||||
|
@ -284,6 +289,11 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
return returnVal.build();
|
||||
}
|
||||
|
||||
public CopyObjectOptions cacheControl(String cacheControl) {
|
||||
this.cacheControl = checkNotNull(cacheControl, "cacheControl");
|
||||
return this;
|
||||
}
|
||||
|
||||
public CopyObjectOptions contentDisposition(String contentDisposition) {
|
||||
this.contentDisposition = checkNotNull(contentDisposition, "contentDisposition");
|
||||
return this;
|
||||
|
@ -354,6 +364,11 @@ public class CopyObjectOptions extends BaseHttpRequestOptions {
|
|||
return options.ifSourceETagDoesntMatch(eTag);
|
||||
}
|
||||
|
||||
public static CopyObjectOptions cacheControl(String cacheControl) {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
return options.cacheControl(cacheControl);
|
||||
}
|
||||
|
||||
public static CopyObjectOptions contentDisposition(String contentDisposition) {
|
||||
CopyObjectOptions options = new CopyObjectOptions();
|
||||
return options.contentDisposition(contentDisposition);
|
||||
|
|
|
@ -62,7 +62,6 @@ public class BindS3ObjectMetadataToRequestTest extends BaseS3ClientTest<S3Client
|
|||
payload.getContentMetadata().setContentLength(5368709120l);
|
||||
object.setPayload(payload);
|
||||
object.getMetadata().setKey("foo");
|
||||
object.getMetadata().setCacheControl("no-cache");
|
||||
object.getMetadata().setUserMetadata(ImmutableMap.of("foo", "bar"));
|
||||
|
||||
HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http://localhost").build();
|
||||
|
@ -70,7 +69,7 @@ public class BindS3ObjectMetadataToRequestTest extends BaseS3ClientTest<S3Client
|
|||
|
||||
assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint(
|
||||
URI.create("http://localhost")).headers(
|
||||
ImmutableMultimap.of("Cache-Control", "no-cache", "x-amz-meta-foo", "bar")).build());
|
||||
ImmutableMultimap.of("x-amz-meta-foo", "bar")).build());
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||
|
|
Loading…
Reference in New Issue