kopia lustrzana https://github.com/gaul/s3proxy
rodzic
542c9b8112
commit
744d126331
|
@ -1313,6 +1313,9 @@ final class S3ProxyHandler extends AbstractHandler {
|
||||||
String headerValue = Strings.nullToEmpty(request.getHeader(
|
String headerValue = Strings.nullToEmpty(request.getHeader(
|
||||||
headerName));
|
headerName));
|
||||||
if (headerName.equalsIgnoreCase(
|
if (headerName.equalsIgnoreCase(
|
||||||
|
HttpHeaders.CACHE_CONTROL)) {
|
||||||
|
contentMetadata.cacheControl(headerValue);
|
||||||
|
} else if (headerName.equalsIgnoreCase(
|
||||||
HttpHeaders.CONTENT_DISPOSITION)) {
|
HttpHeaders.CONTENT_DISPOSITION)) {
|
||||||
contentMetadata.contentDisposition(headerValue);
|
contentMetadata.contentDisposition(headerValue);
|
||||||
} else if (headerName.equalsIgnoreCase(
|
} else if (headerName.equalsIgnoreCase(
|
||||||
|
@ -2060,6 +2063,8 @@ final class S3ProxyHandler extends AbstractHandler {
|
||||||
BlobMetadata metadata) {
|
BlobMetadata metadata) {
|
||||||
ContentMetadata contentMetadata =
|
ContentMetadata contentMetadata =
|
||||||
metadata.getContentMetadata();
|
metadata.getContentMetadata();
|
||||||
|
response.addHeader(HttpHeaders.CACHE_CONTROL,
|
||||||
|
contentMetadata.getCacheControl());
|
||||||
response.addHeader(HttpHeaders.CONTENT_DISPOSITION,
|
response.addHeader(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
contentMetadata.getContentDisposition());
|
contentMetadata.getContentDisposition());
|
||||||
response.addHeader(HttpHeaders.CONTENT_ENCODING,
|
response.addHeader(HttpHeaders.CONTENT_ENCODING,
|
||||||
|
@ -2468,7 +2473,9 @@ final class S3ProxyHandler extends AbstractHandler {
|
||||||
Strings.nullToEmpty(request.getHeader(headerName)));
|
Strings.nullToEmpty(request.getHeader(headerName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.contentDisposition(request.getHeader(
|
builder.cacheControl(request.getHeader(
|
||||||
|
HttpHeaders.CACHE_CONTROL))
|
||||||
|
.contentDisposition(request.getHeader(
|
||||||
HttpHeaders.CONTENT_DISPOSITION))
|
HttpHeaders.CONTENT_DISPOSITION))
|
||||||
.contentEncoding(request.getHeader(
|
.contentEncoding(request.getHeader(
|
||||||
HttpHeaders.CONTENT_ENCODING))
|
HttpHeaders.CONTENT_ENCODING))
|
||||||
|
|
|
@ -30,7 +30,6 @@ import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.s3.S3ClientLiveTest;
|
import org.jclouds.s3.S3ClientLiveTest;
|
||||||
import org.jclouds.s3.domain.S3Object;
|
|
||||||
import org.testng.SkipException;
|
import org.testng.SkipException;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -127,9 +126,4 @@ public final class JcloudsS3ClientLiveTest extends S3ClientLiveTest {
|
||||||
return new URL(String.format("%s/%s/%s", URI.create(endpoint),
|
return new URL(String.format("%s/%s/%s", URI.create(endpoint),
|
||||||
containerName, key));
|
containerName, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertCacheControl(S3Object newObject, String string) {
|
|
||||||
// Cache-Control not supported
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,13 @@ import org.junit.Test;
|
||||||
|
|
||||||
public final class S3ProxyTest {
|
public final class S3ProxyTest {
|
||||||
private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
|
private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
|
||||||
|
private static final Set<String> BLOBSTORE_NO_CACHE_CONTROL_SUPPORT =
|
||||||
|
ImmutableSet.of(
|
||||||
|
"atmos",
|
||||||
|
"rackspace-cloudfiles-uk",
|
||||||
|
"rackspace-cloudfiles-us",
|
||||||
|
"openstack-swift"
|
||||||
|
);
|
||||||
private static final Set<String> SWIFT_BLOBSTORES = ImmutableSet.of(
|
private static final Set<String> SWIFT_BLOBSTORES = ImmutableSet.of(
|
||||||
"rackspace-cloudfiles-uk",
|
"rackspace-cloudfiles-uk",
|
||||||
"rackspace-cloudfiles-us",
|
"rackspace-cloudfiles-us",
|
||||||
|
@ -369,6 +376,7 @@ public final class S3ProxyTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSinglepartUpload() throws Exception {
|
public void testSinglepartUpload() throws Exception {
|
||||||
String blobName = "singlepart-upload";
|
String blobName = "singlepart-upload";
|
||||||
|
String cacheControl = "max-age=3600";
|
||||||
String contentDisposition = "attachment; filename=new.jpg";
|
String contentDisposition = "attachment; filename=new.jpg";
|
||||||
String contentEncoding = "gzip";
|
String contentEncoding = "gzip";
|
||||||
String contentLanguage = "fr";
|
String contentLanguage = "fr";
|
||||||
|
@ -378,6 +386,7 @@ public final class S3ProxyTest {
|
||||||
"key2", "value2");
|
"key2", "value2");
|
||||||
Blob blob = s3BlobStore.blobBuilder(blobName)
|
Blob blob = s3BlobStore.blobBuilder(blobName)
|
||||||
.payload(BYTE_SOURCE)
|
.payload(BYTE_SOURCE)
|
||||||
|
.cacheControl(cacheControl)
|
||||||
.contentDisposition(contentDisposition)
|
.contentDisposition(contentDisposition)
|
||||||
.contentEncoding(contentEncoding)
|
.contentEncoding(contentEncoding)
|
||||||
.contentLanguage(contentLanguage)
|
.contentLanguage(contentLanguage)
|
||||||
|
@ -396,6 +405,10 @@ public final class S3ProxyTest {
|
||||||
}
|
}
|
||||||
ContentMetadata newContentMetadata =
|
ContentMetadata newContentMetadata =
|
||||||
newBlob.getMetadata().getContentMetadata();
|
newBlob.getMetadata().getContentMetadata();
|
||||||
|
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||||
|
assertThat(newContentMetadata.getCacheControl()).isEqualTo(
|
||||||
|
cacheControl);
|
||||||
|
}
|
||||||
assertThat(newContentMetadata.getContentDisposition()).isEqualTo(
|
assertThat(newContentMetadata.getContentDisposition()).isEqualTo(
|
||||||
contentDisposition);
|
contentDisposition);
|
||||||
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
||||||
|
@ -416,6 +429,7 @@ public final class S3ProxyTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMultipartUpload() throws Exception {
|
public void testMultipartUpload() throws Exception {
|
||||||
String blobName = "multipart-upload";
|
String blobName = "multipart-upload";
|
||||||
|
String cacheControl = "max-age=3600";
|
||||||
String contentDisposition = "attachment; filename=new.jpg";
|
String contentDisposition = "attachment; filename=new.jpg";
|
||||||
String contentEncoding = "gzip";
|
String contentEncoding = "gzip";
|
||||||
String contentLanguage = "fr";
|
String contentLanguage = "fr";
|
||||||
|
@ -425,6 +439,7 @@ public final class S3ProxyTest {
|
||||||
"key2", "value2");
|
"key2", "value2");
|
||||||
BlobMetadata blobMetadata = s3BlobStore.blobBuilder(blobName)
|
BlobMetadata blobMetadata = s3BlobStore.blobBuilder(blobName)
|
||||||
.payload(new byte[0]) // fake payload to add content metadata
|
.payload(new byte[0]) // fake payload to add content metadata
|
||||||
|
.cacheControl(cacheControl)
|
||||||
.contentDisposition(contentDisposition)
|
.contentDisposition(contentDisposition)
|
||||||
.contentEncoding(contentEncoding)
|
.contentEncoding(contentEncoding)
|
||||||
.contentLanguage(contentLanguage)
|
.contentLanguage(contentLanguage)
|
||||||
|
@ -459,6 +474,10 @@ public final class S3ProxyTest {
|
||||||
}
|
}
|
||||||
ContentMetadata newContentMetadata =
|
ContentMetadata newContentMetadata =
|
||||||
newBlob.getMetadata().getContentMetadata();
|
newBlob.getMetadata().getContentMetadata();
|
||||||
|
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||||
|
assertThat(newContentMetadata.getCacheControl()).isEqualTo(
|
||||||
|
cacheControl);
|
||||||
|
}
|
||||||
assertThat(newContentMetadata.getContentDisposition()).isEqualTo(
|
assertThat(newContentMetadata.getContentDisposition()).isEqualTo(
|
||||||
contentDisposition);
|
contentDisposition);
|
||||||
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
||||||
|
@ -513,6 +532,7 @@ public final class S3ProxyTest {
|
||||||
public void testCopyObjectPreserveMetadata() throws Exception {
|
public void testCopyObjectPreserveMetadata() throws Exception {
|
||||||
String fromName = "from-name";
|
String fromName = "from-name";
|
||||||
String toName = "to-name";
|
String toName = "to-name";
|
||||||
|
String cacheControl = "max-age=3600";
|
||||||
String contentDisposition = "attachment; filename=old.jpg";
|
String contentDisposition = "attachment; filename=old.jpg";
|
||||||
String contentEncoding = "gzip";
|
String contentEncoding = "gzip";
|
||||||
String contentLanguage = "en";
|
String contentLanguage = "en";
|
||||||
|
@ -522,6 +542,7 @@ public final class S3ProxyTest {
|
||||||
"key2", "value2");
|
"key2", "value2");
|
||||||
Blob fromBlob = s3BlobStore.blobBuilder(fromName)
|
Blob fromBlob = s3BlobStore.blobBuilder(fromName)
|
||||||
.payload(BYTE_SOURCE)
|
.payload(BYTE_SOURCE)
|
||||||
|
.cacheControl(cacheControl)
|
||||||
.contentLength(BYTE_SOURCE.size())
|
.contentLength(BYTE_SOURCE.size())
|
||||||
.contentDisposition(contentDisposition)
|
.contentDisposition(contentDisposition)
|
||||||
.contentEncoding(contentEncoding)
|
.contentEncoding(contentEncoding)
|
||||||
|
@ -542,6 +563,10 @@ public final class S3ProxyTest {
|
||||||
}
|
}
|
||||||
ContentMetadata contentMetadata =
|
ContentMetadata contentMetadata =
|
||||||
toBlob.getMetadata().getContentMetadata();
|
toBlob.getMetadata().getContentMetadata();
|
||||||
|
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||||
|
assertThat(contentMetadata.getCacheControl()).isEqualTo(
|
||||||
|
cacheControl);
|
||||||
|
}
|
||||||
assertThat(contentMetadata.getContentDisposition()).isEqualTo(
|
assertThat(contentMetadata.getContentDisposition()).isEqualTo(
|
||||||
contentDisposition);
|
contentDisposition);
|
||||||
assertThat(contentMetadata.getContentEncoding()).isEqualTo(
|
assertThat(contentMetadata.getContentEncoding()).isEqualTo(
|
||||||
|
@ -564,6 +589,7 @@ public final class S3ProxyTest {
|
||||||
Blob fromBlob = s3BlobStore.blobBuilder(fromName)
|
Blob fromBlob = s3BlobStore.blobBuilder(fromName)
|
||||||
.payload(BYTE_SOURCE)
|
.payload(BYTE_SOURCE)
|
||||||
.contentLength(BYTE_SOURCE.size())
|
.contentLength(BYTE_SOURCE.size())
|
||||||
|
.cacheControl("max-age=3600")
|
||||||
.contentDisposition("attachment; filename=old.jpg")
|
.contentDisposition("attachment; filename=old.jpg")
|
||||||
.contentEncoding("compress")
|
.contentEncoding("compress")
|
||||||
.contentLanguage("en")
|
.contentLanguage("en")
|
||||||
|
@ -575,11 +601,13 @@ public final class S3ProxyTest {
|
||||||
.build();
|
.build();
|
||||||
s3BlobStore.putBlob(containerName, fromBlob);
|
s3BlobStore.putBlob(containerName, fromBlob);
|
||||||
|
|
||||||
|
String cacheControl = "max-age=1800";
|
||||||
String contentDisposition = "attachment; filename=new.jpg";
|
String contentDisposition = "attachment; filename=new.jpg";
|
||||||
String contentEncoding = "gzip";
|
String contentEncoding = "gzip";
|
||||||
String contentLanguage = "fr";
|
String contentLanguage = "fr";
|
||||||
String contentType = "audio/mp4";
|
String contentType = "audio/mp4";
|
||||||
ContentMetadata contentMetadata = ContentMetadataBuilder.create()
|
ContentMetadata contentMetadata = ContentMetadataBuilder.create()
|
||||||
|
.cacheControl(cacheControl)
|
||||||
.contentDisposition(contentDisposition)
|
.contentDisposition(contentDisposition)
|
||||||
.contentEncoding(contentEncoding)
|
.contentEncoding(contentEncoding)
|
||||||
.contentLanguage(contentLanguage)
|
.contentLanguage(contentLanguage)
|
||||||
|
@ -602,6 +630,10 @@ public final class S3ProxyTest {
|
||||||
}
|
}
|
||||||
ContentMetadata toContentMetadata =
|
ContentMetadata toContentMetadata =
|
||||||
toBlob.getMetadata().getContentMetadata();
|
toBlob.getMetadata().getContentMetadata();
|
||||||
|
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||||
|
assertThat(contentMetadata.getCacheControl()).isEqualTo(
|
||||||
|
cacheControl);
|
||||||
|
}
|
||||||
assertThat(toContentMetadata.getContentDisposition()).isEqualTo(
|
assertThat(toContentMetadata.getContentDisposition()).isEqualTo(
|
||||||
contentDisposition);
|
contentDisposition);
|
||||||
assertThat(toContentMetadata.getContentEncoding()).isEqualTo(
|
assertThat(toContentMetadata.getContentEncoding()).isEqualTo(
|
||||||
|
|
Ładowanie…
Reference in New Issue