JCLOUDS-402: Allow Guava MediaType Content-Type

This promotes type-safety.  Keep the String interface for unknown
content types.
This commit is contained in:
Andrew Gaul 2013-06-21 16:50:26 -07:00
parent e868675da4
commit c6d4e6645c
4 changed files with 13 additions and 2 deletions

View File

@ -303,13 +303,15 @@ Options can also be specified for extension modules
blob-builder (if content-length ;; Special case, arg is prim.
(.contentLength blob-builder content-length)
blob-builder)
blob-builder (if content-type
(.contentType blob-builder content-type)
blob-builder)
blob-builder (if calculate-md5 ;; Only do calculateMD5 OR contentMD5.
(.calculateMD5 blob-builder)
(if content-md5
(.contentMD5 blob-builder content-md5)
blob-builder))]
(doto blob-builder
(.contentType content-type)
(.contentDisposition content-disposition)
(.contentEncoding content-encoding)
(.contentLanguage content-language)

View File

@ -26,6 +26,7 @@ import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
import org.jclouds.io.Payload;
import com.google.common.io.ByteSource;
import com.google.common.net.MediaType;
import com.google.inject.ImplementedBy;
/**
@ -119,6 +120,8 @@ public interface BlobBuilder {
PayloadBlobBuilder contentMD5(byte[] md5);
PayloadBlobBuilder contentType(MediaType contentType);
PayloadBlobBuilder contentType(String contentType);
PayloadBlobBuilder contentDisposition(String contentDisposition);

View File

@ -36,6 +36,7 @@ import org.jclouds.io.payloads.PhantomPayload;
import com.google.common.collect.Maps;
import com.google.common.io.ByteSource;
import com.google.common.net.MediaType;
/**
* @author Adrian Cole
@ -205,6 +206,11 @@ public class BlobBuilderImpl implements BlobBuilder {
return this;
}
@Override
public PayloadBlobBuilder contentType(MediaType contentType) {
return contentType(checkNotNull(contentType, "contentType").toString());
}
@Override
public PayloadBlobBuilder contentType(String contentType) {
payload.getContentMetadata().setContentType(contentType);

View File

@ -123,7 +123,7 @@
(is (= "http://localhost/container/path" (str (.getEndpoint request))))
(is (= "PUT" (.getMethod request)))
(is (= "10" (first (.get (.getHeaders request) "Content-Length"))))
(is (nil?
(is (= "application/unknown"
(first (.get (.getHeaders request) "Content-Type"))))))
(deftest sign-put-with-headers-test