/** parses the http response headers to create a new {@link MutableObjectMetadata} object. */ public MutableObjectMetadata apply(HttpResponse from) { BlobMetadata base = blobMetadataParser.apply(from); MutableObjectMetadata to = blobToObjectMetadata.apply(base); addETagTo(from, to); if (to.getContentMetadata().getContentMD5() == null && to.getETag() != null) { Matcher md5Matcher = MD5_FROM_ETAG.matcher(to.getETag()); if (md5Matcher.find()) { byte[] md5 = base16().lowerCase().decode(md5Matcher.group(1)); // it is possible others will look at the http payload directly if (from.getPayload() != null) from.getPayload().getContentMetadata().setContentMD5(md5); to.getContentMetadata().setContentMD5(md5); } } // amz has an etag, but matches syntax for usermetadata to.getUserMetadata().remove("object-etag"); to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL)); return to; }
/** * parses the http response headers to create a new * {@link org.jclouds.s3.domain.internal.MutableObjectMetadata} object. */ public MutableObjectMetadata apply(HttpResponse from) { BlobMetadata base = blobMetadataParser.apply(from); MutableObjectMetadata to = blobToObjectMetadata.apply(base); addETagTo(from, to); if (to.getContentMetadata().getContentMD5() == null && to.getETag() != null) { Matcher md5Matcher = MD5_FROM_ETAG.matcher(to.getETag()); if (md5Matcher.find()) { byte[] md5 = base16().lowerCase().decode(md5Matcher.group(1)); // it is possible others will look at the http payload directly if (from.getPayload() != null) from.getPayload().getContentMetadata().setContentMD5(md5); to.getContentMetadata().setContentMD5(md5); } } // amz has an etag, but matches syntax for usermetadata to.getUserMetadata().remove("object-etag"); to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL)); return to; }
/** * parses the http response headers to create a new * {@link org.jclouds.s3.domain.internal.MutableObjectMetadata} object. */ public MutableObjectMetadata apply(HttpResponse from) { BlobMetadata base = blobMetadataParser.apply(from); MutableObjectMetadata to = blobToObjectMetadata.apply(base); addETagTo(from, to); if (to.getContentMetadata().getContentMD5() == null && to.getETag() != null) { Matcher md5Matcher = MD5_FROM_ETAG.matcher(to.getETag()); if (md5Matcher.find()) { byte[] md5 = base16().lowerCase().decode(md5Matcher.group(1)); // it is possible others will look at the http payload directly if (from.getPayload() != null) from.getPayload().getContentMetadata().setContentMD5(md5); to.getContentMetadata().setContentMD5(md5); } } // amz has an etag, but matches syntax for usermetadata to.getUserMetadata().remove("object-etag"); to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL)); return to; }
/** parses the http response headers to create a new {@link MutableObjectMetadata} object. */ public MutableObjectMetadata apply(HttpResponse from) { BlobMetadata base = blobMetadataParser.apply(from); MutableObjectMetadata to = blobToObjectMetadata.apply(base); addETagTo(from, to); if (to.getContentMetadata().getContentMD5() == null && to.getETag() != null) { Matcher md5Matcher = MD5_FROM_ETAG.matcher(to.getETag()); if (md5Matcher.find()) { byte[] md5 = base16().lowerCase().decode(md5Matcher.group(1)); // it is possible others will look at the http payload directly if (from.getPayload() != null) from.getPayload().getContentMetadata().setContentMD5(md5); to.getContentMetadata().setContentMD5(md5); } } // amz has an etag, but matches syntax for usermetadata to.getUserMetadata().remove("object-etag"); to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL)); String storageClass = from.getFirstHeaderOrNull("x-amz-storage-class"); if (storageClass != null) { to.setStorageClass(StorageClass.valueOf(storageClass)); } return to; }
/** parses the http response headers to create a new {@link MutableObjectMetadata} object. */ public MutableObjectMetadata apply(HttpResponse from) { BlobMetadata base = blobMetadataParser.apply(from); MutableObjectMetadata to = blobToObjectMetadata.apply(base); addETagTo(from, to); if (to.getContentMetadata().getContentMD5() == null && to.getETag() != null) { Matcher md5Matcher = MD5_FROM_ETAG.matcher(to.getETag()); if (md5Matcher.find()) { byte[] md5 = base16().lowerCase().decode(md5Matcher.group(1)); // it is possible others will look at the http payload directly if (from.getPayload() != null) from.getPayload().getContentMetadata().setContentMD5(md5); to.getContentMetadata().setContentMD5(md5); } } // amz has an etag, but matches syntax for usermetadata to.getUserMetadata().remove("object-etag"); to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL)); String storageClass = from.getFirstHeaderOrNull("x-amz-storage-class"); if (storageClass != null) { to.setStorageClass(StorageClass.valueOf(storageClass)); } return to; }
@Test public void testExtendedPropertiesBind() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); 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(); BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); 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()); }
public void testMetadataWithCacheControlAndContentDisposition() throws Exception { String key = "hello"; S3Object object = getApi().newS3Object(); object.getMetadata().setKey(key); object.setPayload(TEST_STRING); object.getMetadata().setCacheControl("no-cache"); object.getMetadata().getContentMetadata().setContentDisposition("attachment; filename=hello.txt"); String containerName = getContainerName(); try { getApi().putObject(containerName, object); S3Object newObject = validateObject(containerName, key); assertCacheControl(newObject, "no-cache"); assertEquals(newObject.getMetadata().getContentMetadata().getContentDisposition(), "attachment; filename=hello.txt"); } finally { returnContainer(containerName); } }
public void testMetadataWithCacheControlAndContentDisposition() throws Exception { String key = "hello"; S3Object object = getApi().newS3Object(); object.getMetadata().setKey(key); object.setPayload(TEST_STRING); object.getMetadata().setCacheControl("no-cache"); object.getMetadata().getContentMetadata().setContentDisposition("attachment; filename=hello.txt"); String containerName = getContainerName(); try { getApi().putObject(containerName, object); S3Object newObject = validateObject(containerName, key); assertCacheControl(newObject, "no-cache"); assertEquals(newObject.getMetadata().getContentMetadata().getContentDisposition(), "attachment; filename=hello.txt"); } finally { returnContainer(containerName); } }