-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Spinning off the discussion about this specific behavior from #61798.
HttpHeaders will remove the header entry during a validating read if it contained only values with new lines, or had a known parser and was just whitespace.
HttpHeaders headers = new HttpRequestMessage().Headers;
headers.TryAddWithoutValidation("Accept", "invalid with new lines\n"); // or string.Empty
Assert.Equal(1, headers.NonValidated.Count);
Assert.False(headers.TryGetValues("Accept", out _));
// The entry doesn't exist anymore even for NonValidated accesses
Assert.Equal(0, headers.NonValidated.Count);This means that validated enumeration results in even more side effects to the request/response.
NonValidated enumeration is not able to report all entries if a validated enumeration occurred before it.
I recommend we change the behavior here such that values containing new lines are never implicitly removed. This should result in more consistent behavior and improve the usability of NonValidated.
This would mean that the user may now observe new-line characters & empty values from TryGetValues (given they were added without validation).
As a nice bonus, the fact we remove these entries is the biggest complication in reintroducing support for thread-safe concurrent reads (#66989 (comment)).