This is a large PR and addresses work item dotnet/corefx#3000. I apologize for not being able to structure it in a series of smaller commits.
The bulk of this PR is switching WinHttpHandler to use the async pattern of calling WinHTTP APIs. This involved a significant restructuring of the code. As part of that, I split up the large WinHttpHandler class into multiple, smaller, helper classes.
While the intent of using async WinHTTP calls is better performance and cancel-ability, this PR has not been fully optimized yet. Due to the schedule of RC1 code complete next week, it's important that this PR get in and get mileage on it in the next few weeks.
There are several TODO items that will be done in later PR's. There is still work being tracked in dotnet/corefx#2165 for various follow-up items. For example, re-conciling the best SafeHandle pattern to use for WinHTTP between WebSockets.Client and WinHttpHandler.
I'm currently using a simple Debug.WriteLine for verbose debug logging which can be turned on/off via environment variable. I plan to switch this to System.Net ETW trace loggers in the next commit and/or PR. But the logging has proved very useful in diagnosing issues.
Please provide feedback. Depending on the feedback, some of it will be marked as follow-up items for future PRs.
Commit migrated from https://github.com/dotnet/corefx/commit/d8e5371a5d0f9f4bb3aa85127cb78adf89dde1fb
Turned on tests:
SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsDeflateCompressed_ExpectedResponse
SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsGZipCompressed_ExpectedResponse
since the issue with clrcompression.dll was resolved a while ago.
Removed a *Nix annotation suppressing a unit test. This is not needed in
the test sources since the WinHttpHandler library and tests are only
supported on Windows and won't run anymore in CI (disabled in CSPROJ
files) for non-Windows platforms.
Commit migrated from https://github.com/dotnet/corefx/commit/b652828b662f0052deeddea9151f34fccafe3d2a
Fixed a couple of bugs discovered in WinHttpHandler where it was not
sending out client SSL certificates. Changed the final parameter to the
X509Certificate2Collection.Find() method to false. I had originally set
this parameter to true. The parameter tells the .Find() API to only
select "valid" certificates from the collection. The problem is that
"valid" also means "trusted by the client". But a lot of client SSL
certificates are not trusted by the client. They are only trusted by the
server since many servers issue client certificates based on a different
trust root.
Added more tests for client SSL certificates.
Commit migrated from https://github.com/dotnet/corefx/commit/4fa89d2b9b8949bdb261909748808180f2fe1ef5
* Add more tests ported from the internal ToF tests.
* Cleanup existing tests to be consistent in style and format as it has
drifted due to many different people working on the tests.
* Disposing the HttpClient object will dispose the handler as well so we
don't need multiple 'using' statements unless we are explicitly testing
dispose ordering semantics.
Commit migrated from https://github.com/dotnet/corefx/commit/ad55c1d5685afc4009cb2481fcc7c5e4f4a551f8
`build.cmd /p:LockDependencies=true` was the start of this change, but some errors with xunit build numbers led to all xunit upgrades being reset back to what they had in master.
project.json changes:
* System.Net.Security\src Switch off of explicit beta versioning, use the same baseline as everyone else. The S.S.C.Algorithms explicit upgrade is no longer required.
* System.Net.Requests\tests didn't build. Looking at the project.lock.json change, it appeared that a System.Net.Http reference was lost, restored it.
* System.Net.Http\tests didn't build. Looking at the project.lock.json change, it appeared that a System.IO.FileSystem reference was lost, restored it.
* System.Net.WebSockets.Client\src didn't build. Looking at the project.lock.json change, it appeared that a System.Collections (4.0.10) reference was lost, restored it.
* System.Diagnostics.TextWriterTraceListener\tests needed the runtime reference to load the correct System.Diagnostics.TraceSource binary.
Commit migrated from https://github.com/dotnet/corefx/commit/cec3a0f2db542bfa9d9c56bf988d966eacc35ad9
Added more http tests to open source from the original internal ToF tests. Some of
the tests should be refactored in the future to avoid Assert'ing multiple
logical things.
Fixed up test namespaces for System.Net.Http and
System.Net.Http.WinHttpHandler.
Commit migrated from https://github.com/dotnet/corefx/commit/e5a017cb6ca01e99b1f1462298bc0cbf60c06ee0
The corefx build used an older beta5 version of DNX which hardcoded the path to bash in dnu, breaking the build on FreeBSD.
Updating DNX to the latest "stable" beta7 release fixes this.
After updating I noticed a few test projects didn't build anymore as they were missing some dependencies in project.json, added those.
Fixesdotnet/corefx#3173
Commit migrated from https://github.com/dotnet/corefx/commit/6df77fdbb6cf8e0d35a3074bb325f7810085daa3
This PR mainly addresses "handle leaks" dotnet/corefx#2963, dotnet/corefx#2762, dotnet/corefx#2793. In investigating the leaks, I discovered that our use of the SafeHandle pattern was not quite right. Native Windows WinHTTP handles wrapped by SafeHandle need additional lifetime management protection to preserve parent-child relationships. Closing the parent handle too early will invalidate the child handle. So, added a SetParentHandle() method to SafeWinHttpHandle to protect against this. This also simplified the passing of handles to the WinHttpResponseStream class.
After adding leak detection, I discovered a race condition caused by an CancellationToken.Register that should not exist in WinHttpHandler.
This inadvertently provided a way for the awaited SendAsync() task to return back to the caller even though the StartRequest() method is still
running.
Added unit tests to validate the behavior assumptions and to track leaks in the WinHttpHandler logic.
This change does not affect the SafeWinHttpHandleWithCallback class that is used by System.Net.WebSocket.Client. But that class is incorrectly using the SafeHandle pattern w.r.t. Dispose() and I will be fixing that in a later PR.
Commit migrated from https://github.com/dotnet/corefx/commit/a75ec027daa53114c788464878e2947ae7d5a65e
This fixes a bug found with chunked uploads using custom content that repeatedly calls Flush() on the stream passed into SerializeToStreamAsync.
This bug was discovered by WCF tests and reported via GitHub: https://github.com/dotnet/corefx/issues/2897
It was a mistake to use the Flush() method on the stream to send the final terminating chunk for the upload since that method can be called by custom content via the SerializeToStreamAsync method. The typical use pattern is that depending on the actual streams involved, upper layer software typically can call Flush() one or more times when writing to a stream. The fix here is to simply leave Flush() as a no-op (which it basically is for the WinHttpRequestStream) and have an internal method to handle the writing of the final terminating chunk.
This fix is being checked into TFS instead of using a GitHub PR. The reason is that the tests for this need to use our current internal server that correctly echoes the request headers in order to verify 'Transfer-Encoding: chunked' was sent by the client. I tried to put this test into the current GitHub tests using the current "http://httpbin.org" test server, but I discovered that httpbin.org doesn't properly echo the request headers when 'Transfer-Encoding' is sent. Instead, it ends up replacing that header and sending back 'Content-Length' (even though we didn't send that in the request headers). We have a backlog work item to port our remaining ToF tests to GitHub over the next several weeks.
[tfs-changeset: 1516976]
Commit migrated from https://github.com/dotnet/corefx/commit/ac9e5d9426ce28216a9d49d0753c8790e7aac0d2
This change updates the assembly versions of all of the corefx assemblies
as needed after we shipped stable versions. Assemblies with API differences
get a minor version bump. Assemblies with only bugfixes get a build version
bump.
In order to facilitate this I had to update the reference assemblies, so I took
the opportunity to port them all to the open.
[tfs-changeset: 1514419]
Commit migrated from https://github.com/dotnet/corefx/commit/40723b795917f2e98b64d45c17effb2546dd0cae
The stable versioned packages use an older codebase currently than the latest pre-release.
That codebase is still using SecureString in System.Private.Networking, but the dependency
was omitted since crypto is still pre-release but networking had to be marked stable for UWP.
This missing dependency was causing tests to fail.
Rather than just list the dependency I am moving these tests back to pre-release packages
for the System.Net contracts, since System.Net packages are under active development
it is better to have the tests running against latest than the stable bits.
Once we have newer versions published we'll update these tests to use those.
Commit migrated from https://github.com/dotnet/corefx/commit/5d9f9d4c6ea450366c7b70af6e6006a401284d14
This change modifies the build to consume the stable version where available.
This disables building the dowlevel packages since we shipped them once as stable and we're done.
From here on out, we'll only build the latest version (except for a servicing event, which would
be handled by syncing to a hash).
I can't rev the package versions in the normal way yet (by modifying the assembly version of the contents)
because that turned out to be too big of a problem to tackle in this change. Instead I added a
parameter to the task that calculates package versions to do the rev for anything that was
stable, but only when building the package itself, not when calculating the dependencies.
This has the downside of not permitting a dependency on a incremented pre-release version if we've
shipped a stable version, but that is a small point in time problem until I can rev the assembly
versions.
[tfs-changeset: 1508664]
Commit migrated from https://github.com/dotnet/corefx/commit/ee1ec2891c7c65b46fa9dfb078636be503bb2a60
This change sets up the layout for having multiple test projects for
WinHttpHandler. It follows the current guidlines as well as working
within the BUILDTOOLS requirements of having ".Tests.csproj" for the
names of the projects.
Also, fixed up some cross-platform definitions in the solutions files
for Http and WinHttpHandler.
After this PR is done, we will be migrating a large set of http
functional tests to GitHub
Commit migrated from https://github.com/dotnet/corefx/commit/42d81c41175ab8832032a2a387b8dc58365604a9
As per the latest security review, this issue captures the following tasks in order to remove insecure automatic redirection of HTTPS -> HTTP in HttpClientHandler/WinHttpHandler. This will also match the current NETCore/NETNative behavior as well.
In general, the security guidance is to remove insecure patterns from new code/platforms. This helps the entire ecosystem become more secure while balancing the needs of app-compat.
1. Change the WinHttpHandler API surface to remove the AutomaticRedirectionPolicy enum 3-state value.
2. Change the name/type of the 'AutomaticRedirectionPolicy' property to 'bool AutomaticRedirection'. This matches the current Framework Design guidelines of fully spelling out words and the word pattern of the 'AutomaticDecompression' property.
3. The default for the AutomaticRedirection property will be true. This value means that all redirects will be followed automatically EXCEPT for https:// to http://. This behavior is different from .NET desktop where https:// to http:// redirects are also followed.
[tfs-changeset: 1498199]
Commit migrated from https://github.com/dotnet/corefx/commit/4c99b29d6718af2de6d5e53869c694054cae161b