blazor-playwright-example icon indicating copy to clipboard operation
blazor-playwright-example copied to clipboard

BlazorTest fails to correctly proxy content headers

Open nullpainter opened this issue 1 year ago • 0 comments

The following code in BlazorTest is failing when a content header (such as Content-Type) is present on the request. This is preventing testing POST / PUT requests:

foreach (var header in request.Headers)
{
   requestMessage.Headers.Add(header.Key, header.Value);
}

The following works, but feels a bit of a bodge:

foreach (var header in request.Headers)
{
  if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value))
  {
      // Populate content headers if they are not added to request headers
      requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value);
   }
}

I've also got this working a bit more elegantly by maintaining a collection of known content headers to use for conditional population.

nullpainter avatar Aug 28 '24 22:08 nullpainter