JCLOUDS-1400: Honor Azure signed URL content type

This commit is contained in:
Andrew Gaul 2018-04-08 23:05:20 -07:00
parent a79499464a
commit fbaacf7b37
2 changed files with 12 additions and 5 deletions

View File

@ -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,7 +88,8 @@ 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());
}
@Deprecated
@ -95,7 +97,7 @@ public class AzureBlobRequestSigner implements BlobRequestSigner {
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
@ -103,10 +105,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");
@ -137,6 +139,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());
}

View File

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