The latest versions of libcurl have HTTP/2 support; this commit enables that to be used from HttpClient via setting the request Version. Setting the Version will now pass along that version preference to libcurl; if it's set to 2.0, libcurl will use HTTP/2 if supported, otherwise it'll fall back to its default (1.1). As part of this I also fixed CurlHandler to pass along v1.0 and v1.1 so libcurl can respect the developer's explicit wishes.
(Note that the HTTP/2 light-up is only available if libcurl supports it. libcurl relies on nghttp2, which needs to be installed, and a version of libcurl needs to be used that's built against it. To test, I built these locally from source.)
Commit migrated from https://github.com/dotnet/corefx/commit/3440aa3cdbd6f82de3746762a08eb796b8b3d90a
By default libcurl drops headers with empty values, as it uses an empty value as a sentinel to mean "remove a previously added header with this key name." If you actually want a header with an event value, it needs to have a semicolon appended to the key name.
Commit migrated from https://github.com/dotnet/corefx/commit/93a9704371ab0b45794f2faa39cefb736c9a71a5
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