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. blob-builder (if content-length ;; Special case, arg is prim.
(.contentLength blob-builder content-length) (.contentLength blob-builder content-length)
blob-builder) blob-builder)
blob-builder (if content-type
(.contentType blob-builder content-type)
blob-builder)
blob-builder (if calculate-md5 ;; Only do calculateMD5 OR contentMD5. blob-builder (if calculate-md5 ;; Only do calculateMD5 OR contentMD5.
(.calculateMD5 blob-builder) (.calculateMD5 blob-builder)
(if content-md5 (if content-md5
(.contentMD5 blob-builder content-md5) (.contentMD5 blob-builder content-md5)
blob-builder))] blob-builder))]
(doto blob-builder (doto blob-builder
(.contentType content-type)
(.contentDisposition content-disposition) (.contentDisposition content-disposition)
(.contentEncoding content-encoding) (.contentEncoding content-encoding)
(.contentLanguage content-language) (.contentLanguage content-language)

View File

@ -26,6 +26,7 @@ import org.jclouds.blobstore.domain.internal.BlobBuilderImpl;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.net.MediaType;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
/** /**
@ -119,6 +120,8 @@ public interface BlobBuilder {
PayloadBlobBuilder contentMD5(byte[] md5); PayloadBlobBuilder contentMD5(byte[] md5);
PayloadBlobBuilder contentType(MediaType contentType);
PayloadBlobBuilder contentType(String contentType); PayloadBlobBuilder contentType(String contentType);
PayloadBlobBuilder contentDisposition(String contentDisposition); 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.collect.Maps;
import com.google.common.io.ByteSource; import com.google.common.io.ByteSource;
import com.google.common.net.MediaType;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -205,6 +206,11 @@ public class BlobBuilderImpl implements BlobBuilder {
return this; return this;
} }
@Override
public PayloadBlobBuilder contentType(MediaType contentType) {
return contentType(checkNotNull(contentType, "contentType").toString());
}
@Override @Override
public PayloadBlobBuilder contentType(String contentType) { public PayloadBlobBuilder contentType(String contentType) {
payload.getContentMetadata().setContentType(contentType); payload.getContentMetadata().setContentType(contentType);

View File

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