aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
847 stars 172 forks source link

Wrong casing in ETag crashes with InvalidOperationException #293

Closed loraderon closed 1 year ago

loraderon commented 1 year ago

I think that the issue has to do with the casing of the ETag response header. It seems like azureedge.net (sometimes) responds with the header Etag instead of ETag.

var client = ClientExtensions.CreateClient();
const string CacheableResource = "https://nexaprod.azureedge.net/dist/assets/brand/images/sliders/highlights_arrow_left.webp";
var response = client.GetAsync(CacheableResource).
    ConfigureAwait(false).GetAwaiter().GetResult();
var responseFromCache = client.GetAsync(CacheableResource).
    ConfigureAwait(false).GetAwaiter().GetResult();
{
  "ClassName": "System.InvalidOperationException",
  "Message": "Error parsing HTTP message header byte 370 of message System.Byte[].",
  "Data": null,
  "InnerException": null,
  "HelpURL": null,
  "StackTraceString": "
at System.Net.Http.HttpContentMessageExtensions.ReadAsHttpResponseMessageAsyncCore(HttpContent content, Int32 bufferSize, Int32 maxHeaderSize, CancellationToken cancellationToken)
   at CacheCow.Client.MessageContentHttpMessageSerializer.DeserializeToResponseAsync(Stream stream)
   at CacheCow.Client.InMemoryCacheStore.GetValueAsync(CacheKey key)
   at CacheCow.Client.CachingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at UserQuery.Main() in C:\\Users\\Anders\\AppData\\Local\\Temp\\LINQPad7\\_omgtoavv\\jqnnqv\\LINQPadQuery:line 32
",
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": null,
  "HResult": -2146233079,
  "Source": "System.Net.Http.Formatting",
  "WatsonBuckets": null
}
loraderon commented 1 year ago

Sorry, this is probably a duplicate of #213