Skip to content

BlazorTest fails to correctly proxy content headers #3

@nullpainter

Description

@nullpainter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions