Headers marked as `HttpHeaderType.Request` were not able to be accessed
via the `Headers.GetValues` method. When looking up a header,
the `HeaderDescriptor` gets set to to `HttpHeaderType.Custom` in
`GetHeaderDescriptor`, but the persisted header in `_headerStore` had
`HeaderType` set to `HttpHeaderType.Request`, so lookups would fail.
This change makes the insert logic consistent with the lookup logic.
Fixesdotnet/corefx#31143
Commit migrated from https://github.com/dotnet/corefx/commit/8917abaf35ea153f4bbf1098d74d02963ef08e76
The HTTP/2 feature is turned off by default on SocketsHttpHandler since the implementation
is not done. It can be enabled via AppContext or environment variable settings. However,
using those settings is not practical because we need a more granular way of turning on
the HTTP/2 feature for running certain tests.
This PR adds a test helper that uses reflection to set the internal _maxHttpVersion field
of SocketsHttpHandler. I also enabled one HTTP/2 test to demonstrate how to use this test
helper method.
Contributes to dotnet/corefx#31496
Commit migrated from https://github.com/dotnet/corefx/commit/2f9483cdf78c8b6319f471ccb09422a2b0248ee7
While investigating other HttpClient/HttpWebRequest proxy-related bugs, I discovered that
HttpWebRequest was not honoring system proxy settings as defined on Windows with IE
settings or on Linux using environment variables.
The problem is due to how HttpClient and HttpWebRequest differ in how they represent
the default behavior of using system proxy settings with the various properties. Fixed
HttpWebRequest so that it will translate the system proxy settings to the internal
HttpClient/HttpClientHandler objects.
I also removed an invalid Assert in HttpConnection. This assert was firing when using a proxy
that was defined on the loopback adapter using IPv6 literal "[::1]". Due to issue dotnet/corefx#28863 with Uri,
the Uri.IdnHost property doesn't have the brackets for IPv6 literals. So, the Assert was
occuring.
I did not add any new CI tests because it is currently not possible to test system proxy settings
in CI since it involves changing machine configuration. But I ran manual tests.
Commit migrated from https://github.com/dotnet/corefx/commit/72119235e294e711871cf453f2ffc66ba17ff23b
* Change netfx to target .NET 4.7.1
* Fix CoreFx.Private.TestUtilities to not reference System.Runtime.InteropServices.RuntimeInformation which is now inbox in netfx
* Fix StackTrace.Tests to be built against netstandard and run against netfx inbox
* Fix ValueTuple configurations to support net461 and add netfx placeholder configuration since in net471 it is now inbox
* Fix projects' package configurations that had netfx (net461) to still support net461 and netfx as a buildconfigurations
* Disable failing tests when running on .NET 4.7.1
* Make netfx target net472 and merge with master
* Update ActiveIssue comments to issue number only
* Workaround packages tests due to not installed targeting pack
* Match NSSupportPackage version to CLI's
* Remove netstandard support lib bin placing to runtime and testhost for netfx, fix reference paths to match new package
* Run UpdateVSConfigurations after merging conflicts with the newly updated SDK projects
* Add net461 package configuration to System.CodeDom
* Add net461 package configuration to System.Configuration.ConfigurationManager
* Add net461 package configuration to System.Security.Cryptography.Xml
* Add net461 package configuration to System.Security.Permissions
* Add net461 package configuration to System.ServiceModel.Syndication
Commit migrated from https://github.com/dotnet/corefx/commit/faad2e63b35bed10fe18195987a413308b97eded
SocketAsyncEventArgs has a few issues with ExecutionContext, presumably stemming from the fact that capturing ExecutionContext in .NET Framework is not a cheap operation. As a result, when this code was written, it was optimized for avoiding calls to ExecutionContext.Capture. The SAEA tries to hold onto a captured ExecutionContext for as long as possible, only re-capturing when either the SAEA is used with a different socket instance or when an event handler is changed. That has several problems, though. First, it largely violates the purpose of ExecutionContext, which is to flow information from the point where the async operation begins to the continuation/callback, but if the context is only being captured when the Socket or handler is changed, then the context isn't actually tied to the location where the async operation begins, and that means that data like that in an AsyncLocal doesn't properly flow across the async point. Second, it means that the SocketAsyncEventArgs (the whole purpose of which is to cache it) can end up keeping state in an ExecutionContext alive well beyond when it should be kept alive, because the SocketAsyncEventArgs is holding onto the ExecutionContext instance until either the Socket or handler is changed.
This commit fixes this behavior. Since ExecutionContext.Capture in .NET Core is relatively cheap (no allocation, primarily just a ThreadStatic access), we now just always capture the context when starting an operation, and then clear it out when completing the operation.
Commit migrated from https://github.com/dotnet/corefx/commit/851a53bee21639cd65e109b72fd5f9ef90cc0f39
SocketsHttpHandler wasn't even trying to send Negotiate/NTLM auth tokens to a proxy. This was due
to some invalid logic regarding the "usingProxy" field in HttpConnection. Reworked this logic to
be clearer about the various kinds of proxy scenarios.
I refactored the loopback proxy server and made it much more robust. It can now handle multiple
requests and multiple connections which helps test against the other handlers whose behavior is
different in this area. I plan to do further work in consolidating the LoopbackServer and
LoopbackProxyServer classes in future PRs.
I created a separate HttpClientHandlerTest.Proxy.cs file and moved many existing proxy tests and
added new tests. The current HttpClientHandlerTest.cs file is still over 3000 lines and needs more
refactoring to make it easier to maintain and track test scenario coverage.
Fixesdotnet/corefx#30330
Commit migrated from https://github.com/dotnet/corefx/commit/ec1671fd7feffe1070a94d9d86379e0dd95ddcdf
To prepare for the work of adding HTTP/2.0 support to SocketsHttpHandler, I deployed a new Azure
server. As with all HTTP/2.0 endpoints, only HTTPS (TLS) is supported.
This server is based on Azure Web Apps instead of Azure Cloud Services (classic). This makes it
easier to scale out and maintain as well as give us a staging environment to validate upgrades to
the test server without affecting the production PR/CI runs.
Although the default for HttpClient/HttpRequestMessage.Version is 2.0, only the older platform handler stacks (WinHttpHandler, CurlHandler, UAP) will send as HTTP/2.0. SocketsHttpHandler is currently just ignoring the version value and using HTTP/1.1 as the request version. When SocketsHttpHandler is modified to support HTTP/2.0, then all default requests by HttpClient will attempt HTTP/2.0. Our existing Azure test server (and loopback server) will still downgrade to HTTP/1.1. But this new test server will use HTTP/2.0.
Commit migrated from https://github.com/dotnet/corefx/commit/58892b9d2d95d6cc3f90811d75248f90e0ff716b
In a few cases, this also highlighted other dead code that could be removed, e.g. a shim export we no longer need. And it highlighted some places where .cs files weren't included in a .csproj but should have been; I've fixed those.
Commit migrated from https://github.com/dotnet/corefx/commit/844415759d3f1525bf1f5d1bd79453c6aa8493f8
To behave similarly to netfx and WinHTTP, which ensure some known methods are sent uppercased. They differ on exactly which, so I've standardized on doing the ones for which HttpMethod has static properties. Since we're paying for this normalization, I've then taken advantage of it to use reference comparisons on the HttpMethod instances where we're later checking for known methods, and I also removed an allocation from HttpMethod's GetHashCode, since we're now storing these in a dictionary which uses GetHashCode.
Commit migrated from https://github.com/dotnet/corefx/commit/02b11fae98fd2d6662e1c490cae8462b0ce1ecdf
A developer can specify that an Expect: 100-continue header be sent even if there's no request content, in which case SocketsHttpHandler dutifully sends the header. In response, a server might still send back a 100 continue status line and an empty line (e.g. "HTTP/1.1 100 Continue\r\n\r\n"), and then send back the final response, including another status line, headers, etc. SocketsHttpHandler isn't expecting the second status line if there wasn't any request content, in which case it ends up misinterpreting everything after the 100 continue status line and empty line as being response body content. That has many bad side effects, including not parsing any of the actual response headers. And since it doesn't get any response headers that indicate the response body is of a known content length or transfer-chunk encoded, it believes the response only ends when the connection is closed. But this is HTTP 1.1, and the server is likely keeping the connection open for reuse, and thus the client hangs.
Commit migrated from https://github.com/dotnet/corefx/commit/909dc9eb3ba829647c45348c85bc9271019c509f
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
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