* refactor some proxy tests using new loppback server and new auth function
* feedback from reviews
* correct split() use. My local build did not fail for what ever reason
* disable ProxyExplicitlyProvided_DefaultCredentials_Ignored as it used to be
* refactor some proxy tests using new loppback server and new auth function
* feedback from reviews
* disable ProxyExplicitlyProvided_DefaultCredentials_Ignored as it used to be
* add test case for dotnet/corefx#27870
* skip new test on WindowNano
* add limit on Split() so it always splits to two tokens to avoid problems with : in the value
* update Split() as it seems not all c# flavors has the righ overload
* small improvement on header split
* feedback from review
Commit migrated from https://github.com/dotnet/corefx/commit/b2a119950cb52dd744f84b552de1da2df07b937b
The PreAuthenticate_FirstRequestNoHeader_SecondRequestVariousStatusCodes_ThirdRequestPreauthenticates tests a bunch of status codes, some of which are sporadically failing in CI with WinHttpHandler. According to the RFC, several of these status codes require that there not be a response body, but the test is sending one, and it would seem there are then race conditions that are causing WinHttp to fail here and there for these status codes, e.g. 204 and 304. This just fixes the test to not send a body.
Commit migrated from https://github.com/dotnet/corefx/commit/ca07fd9545336610e9768d76261c64c67f244721
When choosing what authentication scheme to use, WinHttpHandler picks the most secure scheme supported by the server. When the client does not support this scheme it closes the connection. This fix updates the authentication logic to instead pick the most secure scheme offered by the server that is also supported by the client.
This change also adds a test of the relevant behavior.
Fixes: dotnet/corefx#27672
Commit migrated from https://github.com/dotnet/corefx/commit/6d031a04f3df8fadd5b82d9c23d904182eea94e4
* Use named arguments for more bool arguments
* Dispose of new HttpConnectionPool if we lose race condition
If two threads are racing to create the first connection for a specific pool, one of them will end up creating a pool object that's then discarded. Make sure we dispose it. Right now it doesn't really matter as there aren't any resources in an empty pool that need to be cleaned up, but it's a good measure and will help in the future if that changes.
* Fix SocketsHttpHandler.PreAuthenticate behavior
Previously SocketsHttpHandler.PreAuthenticate was causing SocketsHttpHandler to always add a basic auth header on every request if a basic credential could be retrieved from the supplied credentials. This is not how PreAuthenticate is supposed to work. Rather, the handler is supposed to track credentials that have previously been used to successfully authenticate, and then on subsequent requests use credentials from that successfully-authenticated cache.
* Add more tests
Commit migrated from https://github.com/dotnet/corefx/commit/e2ed932d985badf1551affc868f965d2f774bf4d
When SocketsHttpHandler puts a connection back into the pool, it issues a pre-emptive asynchronous read on the transport stream. This enables us to check whether any unexpected data has arrived on the connection, whether the connection has been closed, etc., and without polling (which could be done with a NetworkStream but not well with an SslStream). However, when we dispose of a connection from the pool, this task will potentially end up getting faulted, and while it won't crash the application by default, it will end up invoking the TaskScheduler.UnobservedException event.
This commit address this by ensuring that we always observe any exceptions that come from the read ahead task when the connection is disposed of (in the rare case where an HttpConnection is instead left for finalization, the event may still be raised, which is arguably a good thing, as the developer should be disposing responses.)
(The alternative would be to stop using the read ahead, and instead poll every time we wanted to know if the connection was still valid. That would mean storing the socket in addition to the stream on the connection, and would mean we might miss some errant data that was already pulled from the socket into an SslStream. It would also mean at least one more syscall for each request, as we'd check whether a connection from the pool was valid. For now I'm sticking with the read ahead.)
Commit migrated from https://github.com/dotnet/corefx/commit/850c1d76e7c5371c5a6e015afa7f25da32f9cdaa
The UseCallback_BadCertificate_ExpectedPolicyErrors tests had been
disabled when running against SocketsHttpHandler. The reason in the
comments was that the tests were not returning the proper
SslPolicyErrors.
These particular tests use external third party servers (*.badssl.com).
Running these tests now against the latest code shows no errors. It's
possible this was a problem related to those external servers. Renabling
the tests for now.
Fixesdotnet/corefx#23137
Commit migrated from https://github.com/dotnet/corefx/commit/a51680e39a871cbdf3f63bbd28adb3d1abe435f5
SocketNetHttpHandler was not filtering down the client certificates when sending in
"Manual" mode. This caused a client certificate to be sent to a server when it
didn't have the proper EKU OID for "Client Authentication".
Changed this so that both "Manual" and "Automatic" modes will use the CertificateHelper
GetEligibleCertificate() API.
Fixesdotnet/corefx#23128
Commit migrated from https://github.com/dotnet/corefx/commit/d0cb45113979a22b216d630dbe9200d19b401691
* Add response drain max time to SocketsHttpHandler
Adds support for a max time limit on how long we'll try to drain a connection before returning it to the pool, and adds a (currently non-public) knob for controlling that limit.
This also fixes a race condition with regards to cancellation and chunked responses. If cancellation was requested after returning the connection to the pool but before we disposed of the cancellation registration, someone else could get the pooled connection and then cancellation of one request could end up canceling the other request.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/4ca662cf7ed1bff8e423839936083838d705008d
* Add folded response header support to SocketsHttpHandler
The feature is deprecated by RFC 7230, but some servers still utilize it, and if they do, SocketsHttpHandler currently fails (WinHttpHandler and the netfx handler both allow it, CurlHandler currently fails as well). This commit updates the header parsing logic to allow for them.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/dc355e96d61d98dee48a809571edda3c1c7e5525
This commit does several things:
- Exposes the new `ValueTask` extensibility model being added in coreclr. The ValueTask-related files will separately be mirrored over to corefx to enable the netstandard build of System.Threading.Tasks.Extensions.
- Adapts all `Stream`-derived types to return `ValueTask` instead of `Task` from `WriteAsync`.
- Changes the new `WebSocket` `SendAsync` method to return `ValueTask` instead of `Task`, and updates the `ManagedWebSocket` implementation accordingly. Most `SendAsync`s on `ManagedWebSocket` should now return a `ValueTask` that's either completed synchronously (no allocation) or using a pooled object. It now uses the underlying transport's new `WriteAsync` overload that returns `ValueTask`.
- Switches more uses of `ReadAsync` and `WriteAsync` over to the new overloads, including in Process, DeflateStream, BrotliStream, File, HttpClient, SslStream, WebClient, BufferedStream, CryptoStream,
- Removed some unnecessary array clearing from various routines using ArrayPool (after the clearing was added we changed our minds and decided clearing was only necessary in very specific circumstances)
- Implements a custom `IValueTaskSource` in Socket, such that async receives and sends become allocation-free (ammortized). `NetworkStream` then inherits this functionality, such that its new `ReadAsync` and `WriteAsync` are also allocation-free (in the unbounded channel implementations; we can subsequently add it in for bounded).
- Implements a custom `IValueTaskSource` in System.Threading.Channels, such that reading and writing are ammortized allocation-free up to one concurrent reader and writer.
- A few random things I noticed as I was going through, e.g. missing ConfigureAwait, some incorrect synchronization in tests, etc.
- Adds a ton of new tests, mainly in System.Threading.Tasks.Extensions, System.Threading.Channels, and System.Net.Sockets.
Commit migrated from https://github.com/dotnet/corefx/commit/6d1671b2cfcf130b7bc6c059bb0508073426532a
* Add MaxResponseDrainSize, and fix a few draining bugs
I've added MaxResponseDrainSize to make the setting configurable rather than a const; I left it internal until the API is approved.
In adding tests for it, I found a few existing bugs in draining that I fixed:
- HttpConnectionResponseContent nulls out its Stream when the Stream is consumed. Then when the response content is disposed, the Stream is null, so it's not disposed, so it's not drained.
- HttpContentReadStream's Dispose wasn't checking whether it was already called, and would kick off a new draining operation if the connection was still associated. So if the stream was disposed multiple times, which happens if the response content and stream are both disposed (since the content disposes of the stream), we end up corrupting the response due to multiple threads concurrently accessing and draining it.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/eb80d133d066e72626643dddb3171bf9bb6a7c42
* Disable SocketsHttpHandler's concurrent content sends
SocketsHttpHandler currently has some support for allowing request content sending to run concurrently with response content receiving. However, we don't actually have a need for this, and there are a lot of subtleties that would need to be made robust, e.g. how to handle exceptions that occur concurrently in the sending and receiving. For now, we're removing it. Unless ExpectContinue is set to true, we just send the content before receiving the response, and if it is set, we start the send and then wait for it once we've received the final status code from the server.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/fecb772f0607dc85afdb782eda1b42ddffcba61b
* Fix fragment handling in HttpClient
SocketsHttpHandler isn't sending fragments, nor is it properly inheriting the fragment from the original request URI into the redirect location URI when the original URI had one and the redirect URI did not, even though RFC 7231 says it must. This commit fixes that for SocketsHttpHandler.
WinHttpHandler also isn't handling this inheritance according to the RFC. It appears that the logic for WinHttpHandler would actually need to be changed in WINHTTP itself, or else WinHttpHandler would need to be changed to do the redirects itself.
Neither CurlHandler or NetFxHandler send fragments at all.
This commit also fixes the test to correctly compare the expected and actual Uris... apparently Uri equality doesn't factor in fragments, so they're first converted to strings. It also updates the test to also validate that the server received the URI with the fragment included.
* Disable the fragments test on WinHttpHandler
Apparently it sometimes doesn't do the "right thing" even in other cases.
Commit migrated from https://github.com/dotnet/corefx/commit/a273be657f6666e333fd902965a56046d6f48018