We haven't seen this set of tests fail often. But when they do, it seems to take a little more
than 30 seconds (31 in this failure case) for the operation to cancel. The original "30" second
number was a guess. But based on busy CI machines, we'll increase the number in the hope of
getting less test failures.
Closes # 28805
Commit migrated from https://github.com/dotnet/corefx/commit/81b0f7764d815fcac8b6667d81cc05a25f6ebe99
The test was hanging on most handlers except for SocketsHttpHandler. It was hanging because
the await'ed task of connecting to the proxy never happened. Except for SocketsHttpHandler,
the other handlers optimize loopback so that if the destination server is on loopback, then it
ignores any proxy setting. The test was using both a loopback destination server as well as a
loopback proxy server.
This test is one of the few tests that do an end-to-end request/response thru a proxy. So, it's
important that we keep the test and have it work on all handlers. Modified the test to use a real
external server destination. The test still uses a loopback proxy server.
I also moved some of the Outerloop tests to Innerloop since those tests were using loopback.
Fixesdotnet/corefx#27746
Commit migrated from https://github.com/dotnet/corefx/commit/2edbc59c653533c1a0ae91882d482ae148cb92be
Similar to PR dotnet/corefx#29988, testing implementation details of SocketsHttpHandler behaviors
doesn't make sense against the other handlers.
Running HTTP tests generally across all the handlers is useful when we're trying to
validate HTTP protocol and API behaviors to be consistent everywhere.
However, testing SocketsHttpHandler implementation details, such as connection-pooling
algorithms, with other handlers leads to brittle tests with random test failures. The
internal code of each handler and native code (i.e. WinHTTP) use different rules
(timeouts, lifetime, etc.) for such low-level connection details.
So it makes sense to only run tests such as this against the code that was written to
match the tests, i.e. SocketsHttpHandler.
Closesdotnet/corefx#27272
Commit migrated from https://github.com/dotnet/corefx/commit/31f7b653fe62317c7edd5c3fc59430462197934d
Running HTTP tests generally across all the handlers is useful when we're trying to validate HTTP protocol and API behaviors to be consistent everywhere.
However, testing SocketsHttpHandler implementation details, such as connection-drain algorithms, with other handlers leads to brittle tests with random test failures. The internal code of each handler and native code (i.e. WinHTTP) use different rules for such low-level connection details.
So it makes sense to only run tests such as this against the code that was written to match the tests, i.e. SocketsHttpHandler.
Closesdotnet/corefx#28424Closesdotnet/corefx#28206
Commit migrated from https://github.com/dotnet/corefx/commit/2c734d6db0a8009150bac59f13960f463528ba76
Issue dotnet/corefx#23782 was opened describing a behavior difference in Linux versus
Windows regarding the final position of a stream after being sent. This
turned out to be a behavior in CurlHandler that we decided to not fix.
This PR adds a test to document the behavior of resending a request body
content object (now possible now since we no longer dispose request content
after send). This test is only validating the default HttpClientHandler
which is SocketsHttpHandler now. It also matches .NET Framework behavior.
Closesdotnet/corefx#23782
Commit migrated from https://github.com/dotnet/corefx/commit/b46045f9132597e1600e3ceafd6bbeb272576a62
Fixed a few bugs in both WinHttpHandler and SocketsHttpHandler regarding the behavior of
'Accept-Encoding' request headers and automatic decompression of response body content.
On Windows 7, native WinHTTP doesn't support automatic decompression. That also means it doesn't automatically append 'Accept-Encoding' request headers. WinHttpHandler was relying on WinHTTP to add those headers. But it wasn't happening on Windows 7. So, now WinHttpHandler will make sure those headers are added if not already present. WinHttpHandler was also always decompressing content even when the encodings in the .AutomaticDecompression property didn't match.
SocketsHttpHandler had a different bug. It would make sure that the 'Accept-Encoding' headers were
present when .AutomaticDecompression was being used. But it wouldn't check for existing headers and duplicate encodings would be present in the outbound 'Accept-Encoding' request header. I.e., it would end up with "Accept-Encoding: gzip, gzip".
In addition to fixing these bugs, I added more tests to both Http Functional and WinHttpHandler Unit
tests (which can simulate running on Windows 7 using the existing mocks).
Fixesdotnet/corefx#29747Fixesdotnet/corefx#26991
Commit migrated from https://github.com/dotnet/corefx/commit/40ce4cb20270f731d7d826291e1edce8d1ce2c37
* 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
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
* 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
- 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
Windows 7 and Windows 2008 R2 support TLS 1.1 and 1.2, but for legacy reasons by default those protocols are not enabled when a developer elects to use the system default. However, in .NET Core 2.0 and earlier, HttpClientHandler would enable them, due to being a wrapper for WinHTTP, which enabled them. Both for compatibility and because we prefer those higher protocols whenever possible, SocketsHttpHandler also pretends they're part of the default when running on Win7/2008R2.
Commit migrated from https://github.com/dotnet/corefx/commit/0c7a1de0448c9dee76723d0bedd90f76c3436662
I couldn't get it to fail locally, but I believe the issue was that sporadically WinHttpHandler would not reuse the original connection, in which case it would either not close the first and the test would hang because nothing was accepting the second connection, or it would close the first and fail because the server was expecting a second request on the connection. This fixes it by using Connection: close on the first response so that the client won't reuse the same connection.
Commit migrated from https://github.com/dotnet/corefx/commit/586cffcdfdf23ad6c193a4bf37fce88a1bf69508
* add bypass list processing
* remove 10.37.129.2
* update assembly references
* add bypass list processing
* remove 10.37.129.2
* update assembly references
* use Regex.Escape to escape . and [. Add more test cases.
* feedback from reviews
* fix some of the style comments. more changes to come.
* feedback from @stephentoub
* use UriHostNameType and IdnHost consistently to possibly avoid allocations. Add new test for various unexpected input
* replace String.Compare with string.Compare
Commit migrated from https://github.com/dotnet/corefx/commit/c9d1ec1764f421f35cfe0bbc71bf2f81bc8f0f8d
By default, .NET Core defaults to allowing TLSv1, TLSv1.1, and TLSv1.2. However, whereas .NET Framework allows a developer to opt-in to SSLv2/SSLv3, .NET Core currently blocks it. This means developers are unable to use .NET Core when they need to communicate with an endpoint they don't control and that's unfortunately limited to one of these protocols, which blocks adoption of .NET Core.
This commit stops blocking these protocols. They're still disabled by default, and compiling against them still results in a deprecation warning, but if a developer chooses to ignore the warning and explicitly sets SslProtocols, they are at least able to use the protocols, subject to whatever the underlying operating system allows (e.g. Windows stops supporting SSLv2 as of v1607).
Commit migrated from https://github.com/dotnet/corefx/commit/3cc6fda0c6abe76eea222c165ebdf816e83df564
* Update IRetainable, OwnedMemory, and MemoryHandle APIs
* Split OwnedMemory into MemoryManager and IMemoryOwner
* Update ReadOnlySequence, ArrayMemoryPool, and BufferSegment
* Update System.Memory and System.IO.Pipeline tests
* Temporarily skipping the failing Pipelines tests until impl is corrected.
* Update the reference assembly to match implementation and cleanup
* Update API compat baseline for UAPAOT and add GenFacadesIgnoreMissingTypes
* Fix the System.Runtime ref
* Add back the Pin methods to the uapaot api compat baseline
* Clone the API compat baseline from uapaot and add it for uap as well.
* Update BuildTools, CoreClr, CoreFx, CoreSetup, ProjectNTfs, ProjectNTfsTestILC to preview3-02630-01, preview3-26330-08, preview3-26330-06, preview3-26330-04, beta-26330-00, beta-26330-00, respectively
* Fix pipelines tests and update the api compat baseline shim for uapaot
* Add empty Unpin override to pipe pool test.
* Fix the System.Net.Http Functional tests
Commit migrated from https://github.com/dotnet/corefx/commit/f592e887e2349ed52af6a83070c42adb9d26408c