JCLOUDS-1400: Honor GCS signed URL content type

Also add GetOptions headers instead of replacing all headers.


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

Branch: refs/heads/master
Commit: 7db5eb5cd06441f5c38017392fcb69580d1b0eb9
Parents: a35fa4a
Author: Andrew Gaul <g...@apache.org>
Authored: Sat Apr 7 15:28:03 2018 -0700
Committer: Andrew Gaul <g...@apache.org>
Committed: Thu Apr 12 22:43:43 2018 -0700

----------------------------------------------------------------------
 .../blobstore/GoogleCloudStorageBlobRequestSigner.java      | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/7db5eb5c/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobRequestSigner.java
----------------------------------------------------------------------
diff --git 
a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobRequestSigner.java
 
b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobRequestSigner.java
index d41de7d..11deb80 100644
--- 
a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobRequestSigner.java
+++ 
b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobRequestSigner.java
@@ -24,6 +24,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.Signature;
 import java.security.SignatureException;
+import java.util.Map;
 
 import javax.annotation.Resource;
 import javax.inject.Provider;
@@ -95,7 +96,8 @@ public final class GoogleCloudStorageBlobRequestSigner 
implements BlobRequestSig
 
    @Override
    public HttpRequest signPutBlob(String container, Blob blob, long 
timeInSeconds) {
-      return sign("PUT", container, blob.getMetadata().getName(), 
GetOptions.NONE, timestamp.get() + timeInSeconds, null);
+      return sign("PUT", container, blob.getMetadata().getName(), 
GetOptions.NONE, timestamp.get() + timeInSeconds,
+            blob.getMetadata().getContentMetadata().getContentType());
    }
 
    private HttpRequest sign(String method, String container, String name, 
GetOptions options, long expires, String contentType) {
@@ -125,11 +127,14 @@ public final class GoogleCloudStorageBlobRequestSigner 
implements BlobRequestSig
       }
       String signature = BaseEncoding.base64().encode(rawSignature);
 
+      for (Map.Entry<String, String> entry : 
options.buildRequestHeaders().entries()) {
+         request.addHeader(entry.getKey(), entry.getValue());
+      }
+
       return (HttpRequest) request
             .addQueryParam("Expires", String.valueOf(expires))
             .addQueryParam("GoogleAccessId", creds.get().identity)
             .addQueryParam("Signature", signature)
-            .headers(options.buildRequestHeaders())
             .build();
    }
 

Reply via email to