Do not reorder HTTP header values#65249
Do not reorder HTTP header values#65249MihaZupan merged 31 commits intodotnet:mainfrom feiyun0112:fix-63833
Conversation
|
Tagging subscribers to this area: @dotnet/ncl |
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
|
This will now additionally allocate a I think we should keep the field as We can also avoid allocating the I also don't believe this will solve #63831 as that deals with the enumeration order when values are both parsed and unparsed. |
|
What I meant is that you would have a field internal object ParsedAndInvalidValues;where that object can be If only a single value is added (common case), the field will store an public bool ContainsParsedValues()
{
object parsedAndInvalidValues = ParsedAndInvalidValues;
if (parsedAndInvalidValues is null)
{
return false;
}
if (parsedAndInvalidValues is List<object> list)
{
foreach (object value in list)
{
if (value is not InvalidValue)
{
return true;
}
}
return false;
}
else
{
return parsedAndInvalidValues is not InvalidValue;
}
} |
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
This is looking a lot better! Thanks for sticking with me here :)
The main missing parts here are changes to HttpHeaderParsers that rely on the storeValue passed to them. Before, they may have been relying on there being a single value, but now it may be a list that includes invalid values.
For example the CacheControlHeaderParser has to be updated to account for the possibility of being passed a List when extracting a possible existing CacheControlHeaderValue. Having more test coverage here would also be great.
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpRequestHeadersTest.cs
Outdated
Show resolved
Hide resolved
MihaZupan
left a comment
There was a problem hiding this comment.
The parsers should still be updated to account for InvalidValues. See #65249 (review)
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderValueCollection.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpRequestHeadersTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderParser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpRequestHeadersTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderParser.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
…eControlHeaderParser.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
…Headers.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderValueCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
|
I don't think this fixes #63831, does it? At least, I didn't see where, and I didn't see a test case for it. Did I miss it? |
It does not. I removed it from the PR description to avoid confusion. |
|
@feiyun0112 It appears this comment has been marked as resolved multiple times - is there an associated change I missed? |
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs
Outdated
Show resolved
Hide resolved
…Headers.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
…Headers.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
* Do not reorder HTTP header values * fix complie error * make the changes @ danmoseley recommended * make the changes @MihaZupan recommended * make the changes @MihaZupan recommended * make the changes @MihaZupan recommended * make the changes @MihaZupan recommended * make the changes @MihaZupan recommended * check array length * fix unit test * Update src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * make the changes @MihaZupan recommended * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderParser.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * chang unit test * GetParsedValueLength * fix build error * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderParser.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * unit test * make changes @geoffkizer recommended * CloneAndAddValue for InvalidValues * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Update src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com> * Final nits Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
fix #63833