Skip to content

Commit 80dbe76

Browse files
committed
Merge pull request #193 from sharwell/fix-192
Fix 192
2 parents fb32d1c + 7cc53f2 commit 80dbe76

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/corelib/Providers/Rackspace/CloudFilesProvider.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,11 @@ public void UpdateObjectMetadata(string container, string objectName, Dictionary
808808

809809
var urlPath = new Uri(string.Format("{0}/{1}/{2}", GetServiceEndpointCloudFiles(identity, region, useInternalUrl), _encodeDecodeProvider.UrlEncode(container), _encodeDecodeProvider.UrlEncode(objectName)));
810810

811-
ExecuteRESTRequest(identity, urlPath, HttpMethod.POST, headers: headers);
811+
RequestSettings settings = BuildDefaultRequestSettings();
812+
// make sure the content type is not changed by the metadata operation
813+
settings.ContentType = null;
814+
815+
ExecuteRESTRequest(identity, urlPath, HttpMethod.POST, headers: headers, settings: settings);
812816
}
813817

814818
/// <inheritdoc />
@@ -1095,10 +1099,7 @@ public void CopyObject(string sourceContainer, string sourceObjectName, string d
10951099
else
10961100
{
10971101
// make sure to preserve the content type during the copy operation
1098-
Dictionary<string, string> sourceHeaders = GetObjectHeaders(sourceContainer, sourceObjectName, region, useInternalUrl, identity);
1099-
string contentType;
1100-
if (sourceHeaders.TryGetValue("Content-Type", out contentType))
1101-
settings.ContentType = contentType;
1102+
settings.ContentType = null;
11021103
}
11031104

11041105
ExecuteRESTRequest(identity, urlPath, HttpMethod.COPY, headers: headers, settings: settings);

src/testing/integration/Providers/Rackspace/UserObjectStorageTests.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,17 @@ private static Dictionary<string, string> GetContainerMetadataWithPrefix(IObject
780780
return FilterMetadataPrefix(metadata, prefix);
781781
}
782782

783+
private static string GetObjectContentType(IObjectStorageProvider provider, string containerName, string objectName)
784+
{
785+
Dictionary<string, string> headers = provider.GetObjectHeaders(containerName, objectName);
786+
787+
string contentType;
788+
if (!headers.TryGetValue("Content-Type", out contentType))
789+
return null;
790+
791+
return contentType.ToLowerInvariant();
792+
}
793+
783794
#endregion
784795

785796
#region Objects
@@ -853,19 +864,23 @@ public void TestUpdateObjectMetaData()
853864
string containerName = TestContainerPrefix + Path.GetRandomFileName();
854865
string objectName = Path.GetRandomFileName();
855866
string objectData = "";
867+
string contentType = "text/plain-jane";
856868

857869
ObjectStore result = provider.CreateContainer(containerName);
858870
Assert.AreEqual(ObjectStore.ContainerCreated, result);
859871

860872
Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(objectData));
861-
provider.CreateObject(containerName, stream, objectName);
873+
provider.CreateObject(containerName, stream, objectName, contentType);
874+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
875+
862876
Dictionary<string, string> metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
863877
{
864878
{ "Key1", "Value 1" },
865879
{ "Key2", "Value ²" },
866880
};
867881

868882
provider.UpdateObjectMetadata(containerName, objectName, new Dictionary<string, string>(metadata, StringComparer.OrdinalIgnoreCase));
883+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
869884

870885
Dictionary<string, string> actualMetadata = provider.GetObjectMetaData(containerName, objectName);
871886
Console.WriteLine("Object Metadata");
@@ -880,6 +895,7 @@ public void TestUpdateObjectMetaData()
880895
{ "Key2", "Value 2" }
881896
};
882897
provider.UpdateObjectMetadata(containerName, objectName, new Dictionary<string, string>(updatedMetadata, StringComparer.OrdinalIgnoreCase));
898+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
883899

884900
actualMetadata = provider.GetObjectMetaData(containerName, objectName);
885901
Console.WriteLine("Object Metadata");
@@ -1311,13 +1327,14 @@ public void TestCopyObject()
13111327
string copiedName = Path.GetRandomFileName();
13121328
// another random name counts as random content
13131329
string fileData = Path.GetRandomFileName();
1330+
string contentType = "text/plain-jane";
13141331

13151332
ObjectStore containerResult = provider.CreateContainer(containerName);
13161333
Assert.AreEqual(ObjectStore.ContainerCreated, containerResult);
13171334

13181335
using (MemoryStream uploadStream = new MemoryStream(Encoding.UTF8.GetBytes(fileData)))
13191336
{
1320-
provider.CreateObject(containerName, uploadStream, objectName);
1337+
provider.CreateObject(containerName, uploadStream, objectName, contentType);
13211338
}
13221339

13231340
using (MemoryStream downloadStream = new MemoryStream())
@@ -1355,9 +1372,8 @@ public void TestCopyObject()
13551372
}
13561373

13571374
// make sure the content type was not changed by the copy operation
1358-
Dictionary<string, string> originalHeaders = provider.GetObjectHeaders(containerName, objectName);
1359-
Dictionary<string, string> copiedHeaders = provider.GetObjectHeaders(containerName, objectName);
1360-
Assert.AreEqual(originalHeaders["Content-Type"], copiedHeaders["Content-Type"]);
1375+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, objectName));
1376+
Assert.AreEqual(contentType, GetObjectContentType(provider, containerName, copiedName));
13611377

13621378
/* Cleanup
13631379
*/

0 commit comments

Comments
 (0)