Azure / azure-storage-net

Microsoft Azure Storage Libraries for .NET
Apache License 2.0
446 stars 370 forks source link

BlobAttributes metadata dictionary should be case insensitive #647

Closed Robar666 closed 5 years ago

Robar666 commented 6 years ago

Since the metadata of a blob are just a bunch of HTTP headers, shouldn't they be case-insensitive (see https://stackoverflow.com/questions/5258977/are-http-headers-case-sensitive )?

Therefore the metadata dictionary: https://github.com/Azure/azure-storage-net/blob/c1966e1cd64d5eb8e40733ebd6b07b6b8e8fb136/Lib/Common/Blob/BlobAttributes.cs#L30 should have a case-insensitive comparer:

this.Metadata = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

We came across this issue, when our client library uploaded a blob where the metadata key was lowercase (e.g. "mymetadatakey") and our server tried to access the metadata:

blob.Metadata.TryGetValue("MyMetadataKey", out var metaDataValue)

This call wasn't successful, since the dictionary uses the default comparer and therefore the value can't be retrieved.

Even the official documentation (https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata ) states:

Note that metadata names preserve the case with which they were created, but are case-insensitive when set or read.

So if the read/writes are case-insensitive, shouldn't the library behave this way?

seanmcc-msft commented 5 years ago

Fixed in version 10.0.3.

Commit: https://github.com/Azure/azure-storage-net/commit/c0e6cb429291a94eb04409a805131e3b200d9869