JCLOUDS-1400: Honor Azure signed URL content type

Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/a35fa4a4
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/a35fa4a4
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/a35fa4a4

Branch: refs/heads/master
Commit: a35fa4a40463c4566cabac020a877958bfdbcf05
Parents: 7d40ced
Author: Andrew Gaul <g...@apache.org>
Authored: Sun Apr 8 23:05:20 2018 -0700
Committer: Andrew Gaul <g...@apache.org>
Committed: Thu Apr 12 22:43:43 2018 -0700

----------------------------------------------------------------------
 .../azureblob/blobstore/AzureBlobRequestSigner.java | 16 +++++++++++-----
 .../blobstore/AzureBlobRequestSignerTest.java       |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/a35fa4a4/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java
----------------------------------------------------------------------
diff --git 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java
 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java
index 0053cf6..55a4080 100644
--- 
a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java
+++ 
b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java
@@ -34,6 +34,7 @@ import org.jclouds.domain.Credentials;
 import org.jclouds.http.HttpRequest;
 import org.jclouds.http.Uris;
 import org.jclouds.http.options.GetOptions;
+import org.jclouds.javax.annotation.Nullable;
 
 import com.google.common.base.Supplier;
 import com.google.common.net.HttpHeaders;
@@ -74,7 +75,7 @@ public class AzureBlobRequestSigner implements 
BlobRequestSigner {
    public HttpRequest signGetBlob(String container, String name, long 
timeInSeconds) {
       checkNotNull(container, "container");
       checkNotNull(name, "name");
-      return sign("GET", container, name, null, timeInSeconds, null);
+      return sign("GET", container, name, null, timeInSeconds, null, null);
    }
 
    @Override
@@ -87,13 +88,14 @@ public class AzureBlobRequestSigner implements 
BlobRequestSigner {
       checkNotNull(container, "container");
       checkNotNull(blob, "blob");
       return sign("PUT", container, blob.getMetadata().getName(), null, 
timeInSeconds,
-            blob.getMetadata().getContentMetadata().getContentLength());
+            blob.getMetadata().getContentMetadata().getContentLength(),
+            blob.getMetadata().getContentMetadata().getContentType());
    }
 
    public HttpRequest signRemoveBlob(String container, String name) {
       checkNotNull(container, "container");
       checkNotNull(name, "name");
-      return sign("DELETE", container, name, null, DEFAULT_EXPIRY_SECONDS, 
null);
+      return sign("DELETE", container, name, null, DEFAULT_EXPIRY_SECONDS, 
null, null);
    }
 
    @Override
@@ -101,10 +103,10 @@ public class AzureBlobRequestSigner implements 
BlobRequestSigner {
       checkNotNull(container, "container");
       checkNotNull(name, "name");
       return sign("GET", container, name, 
blob2HttpGetOptions.apply(checkNotNull(options, "options")),
-            DEFAULT_EXPIRY_SECONDS, null);
+            DEFAULT_EXPIRY_SECONDS, null, null);
    }
 
-   private HttpRequest sign(String method, String container, String name, 
GetOptions options, long expires, Long contentLength) {
+   private HttpRequest sign(String method, String container, String name, 
@Nullable GetOptions options, long expires, @Nullable Long contentLength, 
@Nullable String contentType) {
       checkNotNull(method, "method");
       checkNotNull(container, "container");
       checkNotNull(name, "name");
@@ -135,6 +137,10 @@ public class AzureBlobRequestSigner implements 
BlobRequestSigner {
          request.replaceHeader(HttpHeaders.CONTENT_LENGTH, 
contentLength.toString());
       }
 
+      if (contentType != null) {
+         request.replaceHeader("x-ms-blob-content-type", contentType);
+      }
+
       if (options != null) {
          request.headers(options.buildRequestHeaders());
       }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/a35fa4a4/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java
----------------------------------------------------------------------
diff --git 
a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java
 
b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java
index 45aefa5..b893995 100644
--- 
a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java
+++ 
b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSignerTest.java
@@ -93,6 +93,7 @@ public class AzureBlobRequestSignerTest extends 
BaseRestAnnotationProcessingTest
                request,
                "Content-Length: 2\n" +
                "Date: Thu, 05 Jun 2008 16:38:19 GMT\n" +
+               "x-ms-blob-content-type: text/plain\n" +
                "x-ms-blob-type: BlockBlob\n");
 
       assertEquals(request.getFilters().size(), 0);

Reply via email to