-
Notifications
You must be signed in to change notification settings - Fork 4.9k
handle bad Expires better #36908
handle bad Expires better #36908
Conversation
|
The System.Net.Http.Unit.Tests (not FunctionalTests) are failing. They probably need to be updated due to this change: |
src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
Outdated
Show resolved
Hide resolved
|
I think we need more tests. For example, with this change, this test should pass now? using System.Net.Http;
using System.Net.Http.Headers;
var content = new StringContent("Hello");
content.Headers.Add("Expires", "-1"); // This shouldn't throw an exception anymore?
Console.WriteLine(content.Headers.Expires.ToString()); // should print "-1" or "DateTime.MinValue" ?Also, consider this: content.Headers.Add("Expires", "-1"); // This shouldn't throw an exception anymore or maybe it does?
// vs
content.Headers.TryAddWithoutValidation("Expires", "-1"); // This shouldn't ever throw an exception. |
src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
Show resolved
Hide resolved
|
And more interesting thoughts to consider: using System.Net.Http;
using System.Net.Http.Headers;
var content = new StringContent("Hello");
// content.Headers.Expires should be null value.
content.Headers.TryAddWithoutValidation("Expires", "-1");
// content.Headers.Expires should be non-null value and equal to DateTime.MinValue. |
|
I updated tests for the values and all other tests are passing now. |
Can you also answer my comments/questions above? There are several questions that need clarity about how this PR should address the parsing of the 'Expires' header. |
|
/azp run corefx-outerloop-linux |
|
/azp run corefx-outerloop-osx |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run corefx-outerloop-windows |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
Outdated
Show resolved
Hide resolved
src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
Outdated
Show resolved
Hide resolved
src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs
Show resolved
Hide resolved
|
I can update names. I'm re-visiting this again as content.Headers.Add("Expires", "-1") does not work. |
Does the main use case (receiving 'Expires: -1' from a server) work? I assume that SocketsHttpHandler adds headers using .TryAddWithoutValidation() when adding headers received on the wire. That is the only important use case in my mind. I think it is a bonus, also, if after doing .TryAddWithoutValidation("Expires", "-1") we also get "headers.Expires == DateTimeOffset.MinValue instead of null. It is probably fine (I think) to let .Add("Expires", "-1") fail. I just wanted to make sure we are aware of that and have a test to verify that behavior. |
|
yes, receiving -1 (or other invalid values) does work and it gets turned to MinValue. I'm somewhat worried about unexpected consequences so it would be nice if we don't need to mess up with the header types. I'll update tests and I'll post new update. |
|
added Assert.Equal() to tests and updated test name |
* handle bad Expires better * update tests * internal -> private * feedback from review Commit migrated from dotnet/corefx@82eedbf
fixes #31918
This is attempt to improve handling of Expire header.
Based on the discussion, -1 and 0 will now return DateTimeOffset.MinValue as representation of "same time in back" instead of null. I also added test to verify that if header is missing we still return null;
Second part of this change will treat al derived classes as Custom. That seems to be fine as we always set types when used internally. I added test case for scenario described by @stephentoub