JCLOUDS-1400: Honor GCS signed URL content type

Also add GetOptions headers instead of replacing all headers.
This commit is contained in:
Andrew Gaul 2018-04-07 15:28:03 -07:00
parent a35fa4a404
commit 7db5eb5cd0
1 changed files with 7 additions and 2 deletions

View File

@ -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();
}