mirror of https://github.com/apache/jclouds.git
Add Swift-specific MD5 checksum header
Tested against cloudfiles-us, hpcloud-objectstorage, and swift-keystone. Reference for ETag: https://answers.launchpad.net/swift/+question/157064
This commit is contained in:
parent
da211e257a
commit
c299b8ff61
|
@ -78,6 +78,7 @@ public class CloudFilesBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", authToken).build();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
import org.jclouds.blobstore.binders.BindUserMetadataToHeadersWithPrefix;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlob;
|
||||
|
@ -59,6 +62,17 @@ public class BindSwiftObjectMetadataToRequest implements Binder {
|
|||
// Enable "chunked"/"streamed" data, where the size needn't be known in advance.
|
||||
request = (R) request.toBuilder().replaceHeader("Transfer-Encoding", "chunked").build();
|
||||
}
|
||||
|
||||
byte[] contentMD5 = object.getInfo().getHash();
|
||||
if (contentMD5 != null) {
|
||||
// Swizzle hash to ETag
|
||||
object.getInfo().setHash(null);
|
||||
request = (R) request.toBuilder()
|
||||
.addHeader(HttpHeaders.ETAG,
|
||||
BaseEncoding.base16().lowerCase().encode(contentMD5))
|
||||
.build();
|
||||
}
|
||||
|
||||
request = mdBinder.bindToRequest(request, object2Blob.apply(object));
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ public class SwiftBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("http://storage/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "testtoken").build();
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ public class SwiftKeystoneBlobSignerExpectTest extends BaseBlobSignerExpectTest
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://objects.jclouds.org/v1.0/40806637803162/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007").build();
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public class HPCloudObjectStorageBlobSignerExpectTest extends BaseBlobSignerExpe
|
|||
protected HttpRequest putBlob() {
|
||||
return HttpRequest.builder().method("PUT")
|
||||
.endpoint("https://objects.jclouds.org/v1.0/40806637803162/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007").build();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue