Skip to content

Headers.TryAddWithoutValidation can still have side effects on the value #79915

@blowdart

Description

@blowdart

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When adding an authorization header with TryAddWithoutValidation() to test error handling the value is still trimmed, removing trailing spaces.

Expected Behavior

I would expect that the non-validating function would also not mutate the value in any way, adding without trimming.

This would of course be a breaking change, so I would suggest a new parameter,

public bool TryAddWithoutValidation (string name, string? value, bool leaveMyValueAloneDamnitIKnowWhatIAmDoing=false);

My naming may be a little long winded

Steps To Reproduce

string headerValue = string.Empty();

request.Headers.TryAddWithoutValidation(HeaderNames.Authorization, "Test + " " + headerValue);

// Now check the authorization header and its value will be "Test", not "Test " as expected

Exceptions (if any)

No response

.NET Version

6.0.12

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions