Runtime: HttpResponseHeaders ETag is not parsed

Created on 18 Oct 2018  路  5Comments  路  Source: dotnet/runtime

Hello,

I'm facing an issue when I use HttpClient in a dotnet core application : ETag header does not seem to be parsed although it is present in the raw headers of the response.
I reproduce the bug in a fresh dotnet core console app (.Net Core 2.1) with the following snippet :

using (var httpClient = new HttpClient())
{
    var url = "https://avsagentlabvm8913.blob.core.windows.net/public/blobtest.json";
    var response = await httpClient.GetAsync(url);
    if (response.Headers.ETag == null)
        if (response.Headers.TryGetValues("ETag", out var values) && values.Any())
            Console.WriteLine($"BUG : {values.First()}");
}

As you can see, the code displays an ETag, but the response.Headers.ETag property is null.

area-System.Net.Http bug

All 5 comments

Maybe i found the issue, if ETag isn't "quoted-string" doensn't parse. RFC states An entity tag consists of an opaque quoted string, possibly prefixed by a weakness indicator.
https://tools.ietf.org/html/rfc7232#page-9
https://tools.ietf.org/html/rfc2616#section-3.11

https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs#L372

for https://avsagentlabvm8913.blob.core.windows.net/public/blobtest.json i get(fiddler)

HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Content-MD5: mZFLkyvTelC5g8XnyQrpOw==
Last-Modified: Thu, 18 Oct 2018 07:56:48 GMT
ETag: 0x8D634CF4173D5ED
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 428bd14c-f01e-0042-6acf-667bda000000
x-ms-version: 2009-09-19
x-ms-lease-status: unlocked
x-ms-blob-type: BlockBlob
Date: Thu, 18 Oct 2018 10:43:02 GMT

{}

/cc @rmkerr @davidsh @karelz

@MarcoRossignoli , I think you are right. If I take a raw ETag from headers and execute following code:

new EntityTagHeaderValue(eTag)

There is a parsing exception. In order to avoid this exception, I have to do:
csharp new EntityTagHeaderValue("\"" + eTag "\"")

I believe the .NET code is correct here; per the RFC, ETag values must be quoted.

You're actually hitting an old bug in Azure Storage. Because you are sending an anonymous Get Blob request for blobtest.json without explicitly specifying an API version, the blob service infers the earliest possible version to process the request: 2009-09-19 (you can see this in the HTTP response). Azure Storage did not correctly quote ETag values until service version 2011-08-18 (reference).

If you make a small modification to your repro above to explicitly specify the most recent API version, you can see this fix work:

  var url = "https://avsagentlabvm8913.blob.core.windows.net/public/blobtest.json";
+ httpClient.DefaultRequestHeaders.Add("x-ms-version", "2018-03-28");   
  var response = await httpClient.GetAsync(url);

You can fix this permanently by using the Set Blob Service Properties API to set a DefaultServiceVersion so you don't have to explicitly set the x-ms-version on your anonymous requests.

@ryanerdmann thank's for clarification ~...however ETag parsing seems not "perfect"...i we try with "weak entity tag" throws, i used a sample from https://tools.ietf.org/html/rfc7232#page-9 ETag: W/"xyzzy"~

new System.Net.Http.Headers.EntityTagHeaderValue("W/\"xyzzy\"");

Unhandled Exception: System.FormatException: The specified value is not a valid quoted string.
   at System.Net.Http.Headers.EntityTagHeaderValue..ctor(String tag, Boolean isWeak)
   at System.Net.Http.Headers.EntityTagHeaderValue..ctor(String tag)

~I don't know if is expected or it's a bug.~

EDIT: Never mind...expected

https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.Net.Http/src/System/Net/Http/Headers/EntityTagHeaderValue.cs#L55

@thomaslevesque I think that all clear now...you can close this issue if you want.

@MarcoRossignoli , @ryanerdmann , thank you both and sorry about this false issue, I close it :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzabroski picture jzabroski  路  3Comments

bencz picture bencz  路  3Comments

jchannon picture jchannon  路  3Comments

matty-hall picture matty-hall  路  3Comments

Timovzl picture Timovzl  路  3Comments