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:
Andrew Gaul 2013-06-20 19:45:45 -07:00
parent da211e257a
commit c299b8ff61
5 changed files with 18 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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