From 8f8c6e3d168b43539bb5a503263961b4d46b3c87 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 25 Jul 2012 17:51:32 -0700 Subject: [PATCH] Support range MD5 for get Blob request. --- .../blob/implementation/BlobRestProxy.java | 3 +++ .../blob/BlobServiceIntegrationTest.java | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java index ec291f845b313..93d219bb03ea8 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/blob/implementation/BlobRestProxy.java @@ -651,6 +651,9 @@ public GetBlobResult getBlob(String container, String blob, GetBlobOptions optio builder = addOptionalHeader(builder, "x-ms-lease-id", options.getLeaseId()); builder = addOptionalRangeHeader(builder, options.getRangeStart(), options.getRangeEnd()); builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition()); + if (options.isComputeRangeMD5()) { + builder = addOptionalHeader(builder, "x-ms-range-get-content-md5", "true"); + } ClientResponse response = builder.get(ClientResponse.class); ThrowIfNotSuccess(response); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java index a72111d7853b6..062bd8cf4e00e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/blob/BlobServiceIntegrationTest.java @@ -1226,6 +1226,32 @@ public void getBlobWithIfNotModifiedSinceAccessConditionWorks() throws Exception // Assert } + @Test + public void getBlobWithMD5Range() throws Exception { + // Arrange + Configuration config = createConfiguration(); + BlobContract service = BlobService.create(config); + String expectedMd5 = "+zxkkqBt6HehE3r5suhS1w=="; + + // Act + String container = TEST_CONTAINER_FOR_BLOBS; + String blob = "test"; + service.createPageBlob(container, blob, 4096); + + GetBlobOptions options = new GetBlobOptions(); + options = options.setRangeStart(50L); + options = options.setRangeEnd(200L); + options = options.setComputeRangeMD5(true); + GetBlobResult getBlobResult = service.getBlob(container, blob, options); + + // Assert + assertNotNull(getBlobResult); + BlobProperties blobProperties = getBlobResult.getProperties(); + String actualMd5 = blobProperties.getContentMD5(); + assertEquals(expectedMd5, actualMd5); + + } + @Test public void getBlobPropertiesWorks() throws Exception { // Arrange