CurlHandler's support for pausing the connection needs to be resilient against spurious unpausing. This commit just removes a faulty assert for a condition that is possible and replaces it with proper handling (repausing).
Commit migrated from https://github.com/dotnet/corefx/commit/ce27027eb8924d32b5d75d4c46d36660e98570ee
* Move more tests to the new test server
* Cleanup 'var' coding patterns
* Remove duplicate tests (*Content clas related) that are already covered with the *Content class tests
* Utiilize the newer test server VerifyUpload endpoint which does 'Content-MD5' verification of transmitted payload to the server
as well as payload from the server
* Add GZip related tests in addition to Deflate compression schemes
Commit migrated from https://github.com/dotnet/corefx/commit/773c8ae1db5aa7e5d695a74fb63968382f8529da
Instead of creating 5 safe handles to native code, only allocate a single native handle in EasyRequest. The single native object will hold all the function and user data pointers necessary to invoke the managed callbacks.
Commit migrated from https://github.com/dotnet/corefx/commit/6fa52c6daed5675662140ec23c2e76cd8f64ce5d
Since libcurl defines callbacks with varying signatures from platform to platform, we need to define a signature for the callbacks that doesn't change. Then we register our own native callbacks, which then converts the parameters from the varying signature to the unchanging signature and invokes the managed callback.
Commit migrated from https://github.com/dotnet/corefx/commit/c874d10c29ae61f7e16f8cea327c1ae14f7568ea
.NET Stream.Read() semantics leave it to the implementation to decide how much data to return given a buffer of size N:
https://msdn.microsoft.com/en-us/library/system.io.stream.read(v=vs.110).aspx
"An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached."
The behavior of System.Net HTTP APIs (i.e. .NET Framework) are such that stream reads are able to return as soon as data is available. They don't wait until the provided buffer is full. The current WinHttpHandler was not behaving that way because it didn't call WinHttpQueryDataAvailable before calling WinHttpReadData. WinHttpQueryDataAvailable would indicate how many bytes can be read immediately.
This fix changes the WinHttpResponseStream.Read* methods to use WinHttpQueryDataAvailable before calling WinHttpReadData.
Added both WinHttpHandler unit tests (helps with simulating/testing network errors) and HttpClientHandler functional tests (which will test x-plat).
Fixesdotnet/corefx#1825
Commit migrated from https://github.com/dotnet/corefx/commit/5386014a6b74a8d38010b244f9e9ced96df53b69
Prior to curl 7.39 the case label for CURLOPT_SSL_CTX_FUNCTION was compiled out, resulting in CURLE_UNKNOWN_OPTION. In 7.39 they changed it to always present, but reporting CURLE_NOT_BUILT_IN when the backend SSL provider didn't support that callback.
The code was written based on the behavior of curl 7.43, so didn't know about the legacy behavioral difference.
Commit migrated from https://github.com/dotnet/corefx/commit/e5bf4763ce60bf50c36c2d473baaee76f09c740c
System.Net.WebHeaderCollection already had a SubstringTrim helper that's used instead of Substring(...).Trim() to avoid first creating the substring and then trimming it, instead just offsetting the startIndex and length appropriately to do the Substring once.
I've factored this helper out into Common, added unit tests, cleaned it up a bit, and used it in several more places in System.Net.
Commit migrated from https://github.com/dotnet/corefx/commit/4e45e641c9d97c3a5d3b6fec4f6ffc33a2405fee
Apply same header response trimming done by WinHttpHandler.
Fixesdotnet/corefx#4187
(At some point I'd like to go through and replace all Substring(...).Trim() calls with a more efficient SubstringTrim(...) that doesn't allocate an intermediate string. But in the meantime, this addresses the problem.)
Commit migrated from https://github.com/dotnet/corefx/commit/a5053a14559ea30d224bf9f74892c86435d9166b
Added tests for validating against all standard and custom HTTP verbs. These tests use the new networking test server.
Cosolidated some existing tests that were duplicative. More test porting and reorganzing will be done in later PRs.
Commit migrated from https://github.com/dotnet/corefx/commit/057f0a9bc938606f9e3a24a51f64f3a4fd9bbb55
libcurl+openssl defaults to just using X509_verify_cert, and the chain that came with the TLS handshake.
The X509Chain class has support for a user-defined trust list, downloading intermediate CA certs, and downloading CRLs (which isn't utilized in this change).
The existing approach was not doing CRL checking, and since the Unix X509Chain implementation does not support opportunistic CRL checking, this change leaves that functionality disabled.
Commit migrated from https://github.com/dotnet/corefx/commit/0ac85cd61e98ab684278dc3fe7a882623e207828
While researching dotnet/corefx#3292, I discovered that POST'ing zero length content throws an exception. This was because we were calling WinHttpWriteData() and passing in a zero length for the buffer size. This returns an error back from WinHTTP.
We don't need to call WinHTTP APIs to write zero length data. We simply need to return a completed task back to the caller.
Added tests to verify the fix.
Commit migrated from https://github.com/dotnet/corefx/commit/0776e741430e83fe72bf4be544701f0eeddce042
CurlHandler calls to HttpContext.CopyToAsync with a stream that CopyToAsync should write to asynchronously. If, however, the call to CopyToAsync writes to it synchronously as part of the synchronous call to CopyToAsync, CurlHandler will deadlock.
As a precaution, we ensure that the CopyToAsync call is asynchronous from the perspective of CurlHandler.
Commit migrated from https://github.com/dotnet/corefx/commit/ebad2d3426af24201526263401fb010a78ee60bd
WinHttpHandler was hanging due to blocking on the WinHTTP status callback thread. The blocking was coming from a task continuation resuming on the same thread and subsequently calling a blocking Stream.Write method in a custom HttpContent class being written onto the request stream.
Blocking is not allowed on the WinHTTP callback thread. So any task continuations need to occur on a different thread. The fix is to create the TaskCompletionSources to use RunContinuationsAsynchronously. This allows them to unblock the WinHTTP thread. Additionally, I added some missing ConfigureAwait(false) settings to some await'd operations.
Added a new test which uses a custom HttpContent class that uses a blocking Write() call when serializing onto the request stream.
Fixdotnet/corefx#4077
Commit migrated from https://github.com/dotnet/corefx/commit/babb7c6c65bf1e02dab667cbda80f0e24af21ed8
A change was made to DNX to no longer restore project.jsons
that are in nested folders. This caused my batch update to miss
a number of tests and reference assembly projects.
This fixes the stale lock files, but restore is still broken.
[tfs-changeset: 1540448]
Commit migrated from https://github.com/dotnet/corefx/commit/3622cccc1b22fa1947a72d5126b59864e9d2fd0d
We need a new DNX to understand the latest packages.
We also need to move all "dotnet" projects to use dotnetX.X (generations)
now that the packages no longer have "dotnet" assets.
The new version of DNX dropped support for the aspnetcore
so I needed to update a few projects/packages that depended
on old package versions that had this moniker.
[tfs-changeset: 1540388]
Commit migrated from https://github.com/dotnet/corefx/commit/38f8d7a3ca1ee819c2b8eabb1c07ee4e99683c97
An instance of HttpContentAsyncStream is passed to HttpContent.CopyToAsync. Currently HttpContentAsyncStream is both readable and writable, but reading is only meant for internal usage by CurlHandler's libcurl callbacks. This change codifies that, such that CanRead now returns false and the public Read* methods throw NotSupportedException. Internal reading is done via ReadAsyncInternal.
Commit migrated from https://github.com/dotnet/corefx/commit/c0fbe3c8e4d50bbf57acd330de8eac136d59c013
WCF ends up trying to use Write as part of HttpContent.CopyToAsync implementations. While that should be addressed separately to use WriteAsync, it's possible others are also using Write instead of WriteAsync, and today we throw NotSupportedException from Write. So as to let this at least work, I'm implementing Write to delegate to WriteAsync.
I also noticed we were missing a FlushAsync implementation, so I've added one.
Commit migrated from https://github.com/dotnet/corefx/commit/b1bc8d48484f4104d0ec2c440544620b920b605f
All projects that previously used dotnet have been updated to specify the appropriate generation of the surface area they depend on or in the case of desktop inbox contracts, the generation that includes the set of platforms they can support.
Now all packages contain all generations of API that they have ever shipped.
In doing this I needed to change how we determine package version. Before we ensured all assemblies would have the same version and used that. Now we choose the max.
Additionally I needed to change how we chose which asset to use for netcore50 when the dotnet asset was obscured by a placeholder for a previous netcore release (eg System.Runtime will have placeholders for Win8 since it was inbox there). To do this I wrote a task that uses nuget to evaluate the package assets with and without the placeholders. In this way it chooses the "best" dotnet implementation and reference assembly to use for netcore50.
This new model made my old MSBuild-based validation impossible to carry forward, so I wrote better validation in a task that actually uses Nuget's asset resolution algorithm. This uncovered many existing issues in packages that I have cleaned up. The validation algorithm could use some polish but its working now. Perf is not great, package build went from 15s to ~2 minutes. I'll work on this some more by making it incremental (input: nuspec, output: marker created on success). Profiling shows that most of the time is spent in calling the nuget APIs. I'll see if I can reduce some of this with caching for things that don't change (eg: RID graph). Ultimately I think its a reasonable tradeoff for the types of bugs I can find this way.
[tfs-changeset: 1539216]
Commit migrated from https://github.com/dotnet/corefx/commit/0931c347eb836c9da94d0d5ff9ad7a14403b9738
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
When CURLOPT_HTTPAUTH is set to 'any', libcurl will always try to make more than one call to figure out the
right authentication scheme needed by the server. This breaks the behavior when PreAuthenticate is set to true.
The fix is to iterate over available schemes and set the auth-scheme flags to only those that are available.
Also, while updating the CredentialCache, we ignore ArgumentException (raised when the cache contains the given url and scheme pair)
Throw exception when network credentials are different for auth schemes
Commit migrated from https://github.com/dotnet/corefx/commit/17fdc686de07b9f9711956eea25e6c0c9042cd17