* Add implementation to common
* Shift System.Net.Http to use common HttpDateParser
* Clean up whitespace in affected areas of System.Net.Requests
* Update System.Net.Request to use common Http date parsing
* Switch to InvariantCulture in tests
* Specify type.
* Remove unneeded file.
* Remove unneeded parameter
* Don't cache parameters.
* Let 'r' be handled like in System.Net.Http
System.Net.Http handled the 'r' format by letting a format string that didn't require leading zeros to be used, meaning one format string can be removed from consideration.
Commit migrated from https://github.com/dotnet/corefx/commit/deee13b99d441cf1906397c54d0c5afcf8385d92
Native WinHTTP sometimes uses multiple TCP connections to try other TLS protocols when
getting TLS protocol failures as part of its TLS fallback algorithm. The loopback server
doesn't expect this and stops listening for more connections. This causes unexpected test failures.
I confirmed this investigation comparing with a non-loopback server and WireShark traces. I discussed
this with the WinHTTP team.
SocketsHttpHandler, which uses SslStream for TLS, is able to optimize this and looks directly at
the TLS server-hello to determine if the connection is going to be compatible with the allowed client
TLS protocols. So, it doesn't use multiple TCP connections to determine a final failure outcome.
I also cleaned up the test code removing duplicate tests.
Fixesdotnet/corefx#8538
Commit migrated from https://github.com/dotnet/corefx/commit/226b225df8873b5c7a79d027119871834b24a7d4
* Fix SocketsHttpHandler handling of pooling timeouts with max connections
Fixes two cases:
1. When a pooling timeout (lifetime or idle) is set to 0, we fail to enforce the MaxConnectionsPerServer limit.
2. When MaxConnectionsPerServer is set and the limit is reached, when a request completes and we transfer the connection from the completing request to a waiting request, we fail to check / enforce the connection lifetime limit.
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/50e30118b37db1c3a48a0920e670b9ca5f9631d4
Many dozen of Http tests are failing on UAP test runs. This is not showing up during PR/CI
because the UWP leg only is building the product and test sources and not actually running
any tests. However, the test failures show up in Helix and also when run locally on a dev machine.
So, for now, I'm disabling some of these tests so that the inner and outer test runs will pass.
Contributes to dotnet/corefx#29802Closesdotnet/corefx#27953
Commit migrated from https://github.com/dotnet/corefx/commit/3326f3f24dd083f0966c8f71c7d1e8c2caa1ddae
* Change EnsureSuccessStatusCode to not dispose response content
Historically, this method has always disposed the response content if it was
throwing an exception. The reason documented in the comment really doesn't
make much sense, especially to just dispose the content but not the actual
response object. The developer pattern we advise when getting an HttpResponseMessage
is to wrap it in a 'using' statement or use an explicit .Dispose() call. And
disposing the HttpResponseMessage would always dispose the inner .Content
anyways.
The use case of dotnet/corefx#26684 is that the response content should be available regardless
if this method throws an exception or not. Developers normally don't expect an object
to get disposed (partially in this case) as a side-affect of calling a method on the
object. So, we're changing the behavior to be more consistent generally with other
.NET objects.
Fixesdotnet/corefx#26684
* Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/b0e049cc3db252129a36648780cf78cb0641afbf
* Fix client certificate lifetime handling in tests
This was a difficult bug to track down. Our use of importing PFX files into the
tests has problems due to a combination of issues. The summary is that these
issues cause the private key (which is written to a temp file on disk) to get
corrupted/deleted. This is why we would get random errors about "invalid client
credentials" when using client certificates in HttpClient (or SslStream).
Thanks to @bartonjs for helping me work thru this.
The lifetime of the temp file containing the private key is associated with the managed
X509Certificate2 object that is created. However, our use of X509Certificate2Collection
followed by the use of the .Find() API in
[GetEligibleClientCertificate](https://github.com/dotnet/corefx/blob/dotnet/corefx@10aa8277de2521fb1e6a5b42d053ad8cc947be81/src/Common/src/System/Net/Security/CertificateHelper.cs#L55-L59)
causes new managed objects to get created including both a new collection object and
new certificate objects wrapping the existing native PCCERT_CONTEXT of the old managed
certificate object. This causes lifetime issues for the temp file containing the private
key since the old managed objects are GC'd.
In terms of fixing this for the tests, I've optimized the Configuration.Certificates
helper and removed constructs that we don't actually use in our tests. Switching from
using .Import() on the collection object to actually creating the X509Certificate2
object directly helps with managing the lifetime of the certificate.
I will be doing a follow-up PR to optimze GetEligibleClientCertificate() to switch from
using .Find() and instead directly query the certificates in the original collection.
This will result in less managed objects being created as well as avoid additional private
key lifetime issues for certificates imported that use the default X509KeyStorage.DefaultKeySet
flags.
I also fixed a problem with the test which was always failing on NETFX.
Closesdotnet/corefx#9543
* Remove Mutex
Commit migrated from https://github.com/dotnet/corefx/commit/75ba6cd878b6764e1f400c839271866f7d2a049a
Ran /t:GenerateReferenceSource and undid irrelevant changes, though I kept a few files where the changes were trivial (e.g. whitespace) and it seemed better to just accept the change to stay in sync with GenerateReferenceSource.
In general I only added missing overrides on non-sealed classes, but when there were already overrides included on sealed classes, I added them back for consistency.
Commit migrated from https://github.com/dotnet/corefx/commit/10aa8277de2521fb1e6a5b42d053ad8cc947be81
This newly added test was always failing in NETFX (Outerloop).
.NET Framework has always had a limitation and cannot resolve DNS names with Unicode since it is p/invoking into the 'A' and not 'W' version of the native APIs. The workaround for developers is to use punnyname for the DNS name.
This is currently being tracked with internal bug 125570.
Commit migrated from https://github.com/dotnet/corefx/commit/8ab4f2c1b3bddf79ea3d206a0fec8444f0af167a
This should help developers debug several common scenarios:
- Pre-authentication credentials rejected
- No match between client and server supported schemes
- Missing or invalid digest tokens
It also logs the value of the www-authenticate header received and the scheme selected, which should help detect a large number of errors.
Commit migrated from https://github.com/dotnet/corefx/commit/e160ef76df64a2114addf774a05af2f995f18bca
* Comment on awaits that don't need ConfigureAwait(false)
- Add comments to several awaits on tasks where ConfigureAwait is unnecessary for a variety of reasons
- Rather than commenting, change one await to GetAwaiter().GetResult() where we know the task is already completed (rather than just commenting to that effect)
* Add missing awaits to XmlTextReaderImplAsync
Commit migrated from https://github.com/dotnet/corefx/commit/b758c3b1f1293ada2e46f9e221be0b392838cc41
We have Brotli_DecompressesResponse_Success which just uses a loopback server. I'd added Brotli_External_DecompressesResponse_Success as a way to test against another Brotli implementation, but that's not really something we need to do in the System.Net.Http tests; rather, it's up to the System.IO.Compression.Brotli tests to ensure compliance. Given that, and this tests ends up causing failures when httpbin.org goes down, I'm just deleting it.
Commit migrated from https://github.com/dotnet/corefx/commit/e85573f9b778ba65925f17da6fc485bb43d2c055
* Add two missing ConfigureAwait(false) calls in SocketsHttpHandler
ChunkedTransferEncodingReadStream's ReadAsync had one await missing a ConfigureAwait(false). If there's a synchronization context set on the calling thread, this results in a continuation being created that posts back to that context, which can cause problems (e.g. deadlocks) if that context is blocked, e.g. if the synchronous Read method is being used to block waiting for ReadAsync to complete. The fix is simply to add `.ConfigureAwait(false)`.
As long as I was fixing that, I also reviewed all `await`s in SocketsHttpHandler and found one more that was missing `.ConfigureAwait(false)`, in HttpConnectionPool's EstablishProxyTunnel, and so fixed that, too.
And added some tests.
* Refactor ContentMode support in tests
Commit migrated from https://github.com/dotnet/corefx/commit/9e8c200f0888a1db590da8ffa026aa7384771611
* Clean dead code in System.Net
* More cleaning
* Clean dead code for HttpListener
* Clean dead code for Mail
* Clean dead code in Http
* Clean dead code for NetworkInformation
* Clean more dead code
* Various fixes
* Build fix
* Restore field
* var -> string
Commit migrated from https://github.com/dotnet/corefx/commit/71cc1ae8ba02b7b71878cb69a50c667c8ed0f50f
We had a minor optimization here, but there's a long-standing issue with Socket.ConnectAsync where it's leaving for finalization a socket when the connect with an IP address fails. It's more important to address that issue, and using DnsEndPoint does so (it's also the code we want, anyway).
Commit migrated from https://github.com/dotnet/corefx/commit/b399fe53343295ccf475262552b6d36beafb2b4e
- Add “Connection: close\r\n” response header in more cases where the loopback server explicitly closes a connection, and in particular where the client makes multiple connections.
- Change several Task.WaitAlls on paired tasks to instead use our WhenAllOrAnyFailed helper.
Commit migrated from https://github.com/dotnet/corefx/commit/cebcf436358600a4808656b142a74f57d1e8f6f0
- We were using WriteAsciiStringAsync in one place we shouldn't have been. Change it to WriteStringAsync.
- We were potentially overflowing in a multiplication on MaxResponseHeadersLength if it was set to a very large value. Changed it to use long multiplication and to cap the max length at int.MaxValue.
- We were accidentally using DateTimeOffset.Now instead of UtcNow when getting the current time during stale pool removal. Change to UtcNow.
- We had an unnecessary/unreachable catch block. Remove it.
- In a race condition where the handler and thus its pool manager was disposed while the cleaning timer callback was in flight (either already queued or already running), we could potentially dispose of the timer and then the callback attempt to change the timer and incur an ObjectDisposedException that would go unhandled on a thread pool thread. One fix would be to track disposal under the same lock that's used to mutate the cleaning timer, but that incurs the cost of tracking disposal and taking a lock on disposal in order to deal with a rare race condition (that we've never actually seen happen). Instead, I opt to simply catch and eat any ODEs that occur.
- If either of the connection lifetime values are set at 0, we avoid putting connections back into a pool and thus also avoid creating the cleaning timer. But we're still putting the created pool into the pools collection, which in theory in an extreme case could be a leak. The fix is simply to not store the pool into the pools in this case.
Commit migrated from https://github.com/dotnet/corefx/commit/c998e559dc3682bda42bedd8379442f1e457d136
This PR will reduce the calls to WinHTTP GetProxyForUrl() if a previous call recently discovered
no PAC file within a certain timeframe. We call this API when "Automatically detect settings"
is turned on. The default configuration on Windows has this proxy setting always turned on. This
is ironic given that most network environments don't have a PAC file on the network. So, it's
important to try to optimize this common case on customers' networks.
Initial testing shows at least a 2x speed improvement with these changes.
I did not use any locking mechanisms since those would drag down performance. In the worst case,
any race condition would mean we might call GetProxyForUrl() an extra time. But since we're only
filtering on ERROR_WINHTTP_AUTODETECTION_FAILED, it is unlikely to actually change over time.
That particular error means that the WPAD protocol was able to complete on the network, but the
answer discovered is that there is no PAC file registered on the network.
Fixesdotnet/corefx#28543
Commit migrated from https://github.com/dotnet/corefx/commit/712d3065cef7f28eae96a578b8bd73870e9b2cd5
As part of looking at the usability of .NET Core network logging (compared to
.NET Framework), I did a walkthru of the current logging in SocketsHttpHandler.
I noticed some inconsistencies in how the NetEventSource logging is being used.
For the 2.1 release, I wanted to at least add more logging to some key areas
including places where we ignore errors/exceptions.
There is still more work to do to improve the logging to make it useful for
developers. This includes doing a better job at logging for System.Net.Sockets
as well as looking into other tool options besides PerfView to look at the traces.
I also fixed the sample script for using starting the traces using Windows logman.
The default log buffer size is too small even for for simple traces. Now, using PerfView
on all the System.Net.* traces no longer shows an error about traces being dropped.
Commit migrated from https://github.com/dotnet/corefx/commit/158ed4d059a875e6828c176ce7ecc4a221b331e3
* Update the System.Runtime and System.Memory ref based on new buildtools
* Fix HttpContent TryGetBuffer and update System.Runtime ref
* Update System.Memory ref and fix PipeAwaitable (assign CancellationTokenRegistration)
* Fix 'use of unassigned local' error in System.Memory performance tests
Commit migrated from https://github.com/dotnet/corefx/commit/bd1911e9b3bf104fd9821a4fc68ea1baafe780ef