WinHttpHandler was currently ignoring the `HttpRequestMessage.Version`
property and was always sending out requests using 'HTTP/1.1' which is the
default for winhttp.
This fix now will look at the request message `Version` property and
send out the request using either 1.0 or 1.1. If neither of these
versions are specified, then the request is sent out using the default
winhttp version (which is currently 1.1 as of Windows 10).
Note: The .NET Framework (Desktop) will throw an exception if neither
1.0 nor 1.1 version is specified. Currently CoreFx including NETNative,
WinHttpHandler and CurlHandler will simply use a default instead of
throwing. While this is different behavior than Desktop, it is more
desirable in the long run.
There is a separate issue dotnet/corefx#4870 to add HTTP/2.0 support to WinHttpHandler.
Fixesdotnet/corefx#4754
Commit migrated from https://github.com/dotnet/corefx/commit/f48989bbe10dd4b24a9e3b085672c30b5251cda6
My previous change to add HTTP/2 multiplexing broke some System.Net.Http functionality on CentOS, or more specifically when using an old version of libcurl that's in our CentOS 7.1 image.
That version of libcurl is from before HTTP/2 multiplexing was introduced. When multiplexing was added to libcurl, one of the existing libcurl functions (curl_multi_setopt) was changed such that if you were to pass in the HTTP/2 multiplexing option (which didn't exist at the time), due to the way the method was implemented, you'd end up opting in to HTTP 1.1 pipelining rather than having the option just be ignored. This is not the desired behavior and ends up breaking behaviors where we issue multiple HTTP 1.1 calls on the same multi handle concurrently.
This fix exposes from the native shim whether we're using a version of libcurl that supports HTTP/2 and that knows about the multiplexing option, and only configures the multi handle for multiplexing in that case.
Commit migrated from https://github.com/dotnet/corefx/commit/6d7793e3c24a779c5dde9e9b9419c2e452c32e6c
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