MackinnonBuck / blazor-playwright-example

A sample demonstrating how to use Playwright to end-to-end test a Blazor app
16 stars 3 forks source link

BlazorTest fails to correctly proxy content headers #3

Open nullpainter opened 1 month ago

nullpainter commented 1 month ago

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.