Commit Graph
2312 Commits
Author SHA1 Message Date
stephentoub 7330010faf Improve memory usage of HttpClient's StreamToStreamCopy
Copying between streams represents one of the larger sources of memory allocations and copying in HttpClient. HttpClient has its own stream-to-stream copy implementation, but there are ways we can significantly improve it based on typical usage within HttpClient.  This commit does the following:
- Previously it would special case when both the source and destination stream were MemoryStreams, but even in that case it would allocate a temporary buffer and do a Read/Write loop to copy between them, and even then it's relatively rare to copy from a MemoryStream to a MemoryStream.  Instead, if the source stream is a MemoryStream and we can get its buffer, we can do a single write to the destination (regardless of what kind of stream it is), avoiding the need for multiple read/writes and for the temporary buffer.  If we can't get its buffer but its length is known to be less than or equal to the requested buffer size and it's positioned at the beginning, we can simply ToArray the source and still do a single write to the target.
- If the destination is the special LimitMemoryStream, used for buffering output, and if that LimitMemoryStream was pre-sized based on the response having a Content-Length, then rather than allocating a temporary buffer and repeatedly copying from the source stream into that buffer and copying from the buffer into the memory stream, we can instead give the destination's buffer directly to be read into by the source, avoiding the temporary buffer and the extra copies.  This is a very common case.
- If the source does not need to be disposed after the copy, rather than doing our own copy loop, we can instead ask the source to use its CopyToAsync implementation to copy to the destination stream.  Worst case this will be exactly what we were previously doing, but best case the source has its own CopyToAsync override that's more efficient.
- When constructing a LimitMemoryStream, if the Content-Length isn't known, we were explicitly passing a 0 capacity to the base, which causes it to allocate a new zero-length array; I've added a ctor to avoid that.

Also avoids some unnecessary array allocations and copies while getting data from buffered content.


Commit migrated from https://github.com/dotnet/corefx/commit/d2502ce05032ae83c5675e2cd4b27ca2fb6706fa
2016-03-30 19:07:00 -04:00
Stephen Toub 682b0c05d6 Merge pull request dotnet/corefx#7318 from stephentoub/multiagent_keepalive
Improve serial throughput of HttpClient on Unix

Commit migrated from https://github.com/dotnet/corefx/commit/d82841e0604842d816ce642a56d0485be2146eaa
2016-03-30 17:59:55 -04:00
Stephen Toub c7897db0b5 Merge pull request dotnet/corefx#7337 from stephentoub/httpclient_tests
Add more tests for HttpClient

Commit migrated from https://github.com/dotnet/corefx/commit/fc0919e2471a8b99958245dcfd23f79481c02bd9
2016-03-30 15:47:09 -04:00
Stephen Toub 1a0043261b Merge pull request dotnet/corefx#7344 from stephentoub/update_packages
Update packages to rc3-23930-00

Commit migrated from https://github.com/dotnet/corefx/commit/a4c9148e413dba2a755c64e6b39071434b3f39f4
2016-03-30 15:30:36 -04:00
Stephen Toub a2690a78fc Merge pull request dotnet/corefx#7348 from stephentoub/fix_baseaddress_nullref
Fix NullReferenceException in HttpClient.BaseAddress when logging enabled

Commit migrated from https://github.com/dotnet/corefx/commit/51a2f649d0d4bbeb368772d7d20b78b0cffa02aa
2016-03-30 13:03:26 -04:00
Stephen Toub 923713b831 Merge pull request dotnet/corefx#7315 from stephentoub/httpclient_async
Refactor HttpClient with async/await

Commit migrated from https://github.com/dotnet/corefx/commit/83af68c6936dea7b561e3f198c6634c85dd539d4
2016-03-30 09:44:45 -04:00
stephentoub b0db0c1bed Fix NullReferenceException in HttpClient.BaseAddress when logging enabled
Commit migrated from https://github.com/dotnet/corefx/commit/71a9f353fbedc751b7dfccce2d68a4d134950b80
2016-03-30 08:33:29 -04:00
stephentoub 99e0ca33de Address PR feedback
Switch to avoid network requests when possible, and bring line coverage up to 100%.


Commit migrated from https://github.com/dotnet/corefx/commit/71e246929f5ae99bbba8611b7a5239a041b94f42
2016-03-30 08:18:40 -04:00
stephentoub dabfe7fc9d Update packages to rc3-23930-00
Commit migrated from https://github.com/dotnet/corefx/commit/64a2b6c70977e33b4e8fb90e8f5d3b019b843e61
2016-03-30 07:30:59 -04:00
stephentoub a4d7a22225 Add more tests for HttpClient
To have more confidence while refactoring, added more HttpClient coverage, in particular of error paths.  Brings HttpClient line coverage from 64.7% to 98.3%, and branch coverage from 42.3% to 78.7%.


Commit migrated from https://github.com/dotnet/corefx/commit/2b88030aa1d2e7cb0b679e871fc4d0613ebbbf02
2016-03-29 19:34:21 -04:00
Stephen Toub a2050259da Merge pull request dotnet/corefx#7285 from stephentoub/cookie_allocs
Reduce allocations in CookieContainer.GetCookieHeader

Commit migrated from https://github.com/dotnet/corefx/commit/f22362dfaa200f3332048d78ffc3bef30207bfc6
2016-03-29 11:46:16 -04:00
stephentoub 0641064aa3 Improve serial throughput of HttpClient on Unix
HttpClient on Unix has a thread dedicated to multiplexing the processing of any number of concurrent requests on that client.  When a request comes in and that worker thread isn't running, a worker is spun up, and that worker will service any number of requests that come in while it's up.  Then, when requests quiesce and there's no more processing to be done, the worker goes away.  If more work later arrives, a new worker is spun up.

This is done to avoid burning a thread per HttpClient when there's no work to be done on that client.  It works well for bursts of activity as well as for sustained concurrent usage.  However, if the client is used for a sequence of requests, one after the other, there's a good chance that the worker will go away between requests, requiring a new worker to be spun up for each.  This has non-trivial costs, both in terms of CPU processing and in terms of managed and native resource allocation/deallocation.

This commit enables a worker to briefly pause before exiting, blocking for a short period of time for new work to arrive rather than simply exiting.


Commit migrated from https://github.com/dotnet/corefx/commit/d3fc3d151da4d1573372b2ab82c7b2aa52eaa5d8
2016-03-29 11:24:37 -04:00
stephentoub 2b5cd19543 Refactor HttpClient with async/await
This commit addresses just the HttpClient class and not the rest of the library, but those can follow.  When HttpClient was initially written, async/await didn't exist, and it was written to use ContinueWith.  By switching to async/await, we can both improve the readability and maintainability of the code and improve performance.


Commit migrated from https://github.com/dotnet/corefx/commit/3860eab0d26527b0e5b931ef4084d40f2886ccc7
2016-03-29 08:22:34 -04:00
stephentoub cd7f206733 Port Cookie changes to Http's cookie.cs
Per PR feedback.


Commit migrated from https://github.com/dotnet/corefx/commit/01e5c74e5d671ebb65035bc83a556ac9760d0a70
2016-03-28 22:46:55 -04:00
Stephen Toub 4a71162a4e Merge pull request dotnet/corefx#7292 from stephentoub/multipart_strings
Remove unnecessary string allocations in MultipartContent

Commit migrated from https://github.com/dotnet/corefx/commit/5965294eaa236d733ade3663ae229b3896c74c9b
2016-03-28 07:25:16 -04:00
stephentoub 63bf484561 Replace HttpContent.CreateCompletedTask with Task.CompletedTask
We can just use Task.CompletedTask, rather than creating a new TCS and its Task each time.


Commit migrated from https://github.com/dotnet/corefx/commit/8ec83fc40be9f495880e97b212e50376aab07e9c
2016-03-27 22:45:40 -04:00
stephentoub d156fea268 Remove unnecessary string allocations in MultipartContent
More low-hanging fruit.  When building up its output, MultipartContent is already using a StringBuilder, but it's creating temporary intermediate strings which it then writes to the StringBuilder, rather than just adding the constituent pieces to the StringBuilder directly.  And when computing the length of the output, it's again generating lots of intermediate strings, when it could instead just measure the size of each of the constituent pieces.


Commit migrated from https://github.com/dotnet/corefx/commit/47e9bbeab66b38b21e512243b5ed16590156d35b
2016-03-27 22:24:26 -04:00
Stephen Toub 1b313893c6 Merge pull request dotnet/corefx#7282 from stephentoub/cbt_curl
Ensure CurlHandler sets CBT even on fast verification path

Commit migrated from https://github.com/dotnet/corefx/commit/f4e984567acfb1672ba023110fdf6db5f34260b4
2016-03-27 08:27:04 -04:00
stephentoub 753c12bd76 Ensure CurlHandler sets CBT even on fast verification path
When we get called back by libcurl to verify the server's certificate, we try to take a fast path where we use OpenSSL's certificate verification rather than doing our own, which is more comprehensive but also slower.  However, when we added that fast path, we inadvertently ended up not setting the Channel Binding Token in that case, only doing so in the fallback path.  This fixes that, moving the configuring of the CBT up to before we ask OpenSSL to verify the cert.


Commit migrated from https://github.com/dotnet/corefx/commit/bb26ba8b5375e76d00db8b371abb6e273e7b4019
2016-03-26 22:36:02 -04:00
Stephen Toub c3b17bf861 Merge pull request dotnet/corefx#7266 from stephentoub/channelbinding_alloc
Lazily allocate ChannelBinding in CurlHandler

Commit migrated from https://github.com/dotnet/corefx/commit/ef6bac6ecc0a7bd3df0daee6b1eeec5a091f5a8b
2016-03-26 22:25:31 -04:00
stephentoub 63c1aa88e7 Avoid creating CurlChannelBinding description until needed
Today CurlChannelBinding creates the result of ToString when the token is set into it.  Getting the description of the binding is rare compared to setting a token into the binding, so just create the string when it's requested.

Also a bit of miscellaneous cleanup in related code.


Commit migrated from https://github.com/dotnet/corefx/commit/49c31a87c41c326788162b7aa148b01f1d89c796
2016-03-26 07:59:48 -04:00
stephentoub 92156d0a5d Lazily allocate ChannelBinding in CurlHandler
This SafeHandle is only needed when using HttpContent-derived types that care about TransportContext, which is not a common case.  Lazily-allocate it.

Just as an example, before this change, it was being allocated during ~50 tests.  After this change, it's allocated just once, in the test explicitly verifying the binding.


Commit migrated from https://github.com/dotnet/corefx/commit/900a3664cf4c574e26144b3cf46db2bcf93fe394
2016-03-26 07:00:19 -04:00
stephentoub aa64955b41 Update packages to rc3-23925-00
Commit migrated from https://github.com/dotnet/corefx/commit/268eea1b538fa80a0042a1eabc4e51c84473d7b0
2016-03-25 20:23:47 -04:00
chcosta 3ca970db0f Merge pull request dotnet/corefx#7249 from chcosta/snh_rid
Update PTR to Unix for System.Net.HTTP

Commit migrated from https://github.com/dotnet/corefx/commit/2dfc9536b6725880ac1804187834aefcd0f96213
2016-03-25 15:04:57 -07:00
stephentoub 11bb3f3c94 Remove and replace some stale [ActiveIssue(...)]
Remove some stale [ActiveIssues] where the tests now pass.

Replace some others with [PlatformSpecific], where the behavior is deemed to be "by design" / accepted.

And update a few issue numbers.


Commit migrated from https://github.com/dotnet/corefx/commit/9c13b0c9389189d86fb2d270c28660946b3ae80c
2016-03-25 15:24:49 -04:00
Christopher Costa 55db55ebd9 Update PTR to Unix for System.Net.HTTP
Commit migrated from https://github.com/dotnet/corefx/commit/fe7b507aee4b268d52ff025c1a05643aac360806
2016-03-25 10:14:51 -07:00
stephentoub 57672b1925 Add assert for status code to cookies test
This test failed once, and I expect it was just due to a network blip that caused the request to fail, but since we're not currently checking the http status code, I can't be sure.  As such, I'm just adding another assert for the expected status code, and if this repros again, we'll know whether that's the issue.


Commit migrated from https://github.com/dotnet/corefx/commit/50b2ce5699eb7034a033b3d125ad62bf03b23458
2016-03-24 19:07:44 -04:00
stephentoub e91101e062 Add tests for certificate revocation and non-OpenSSL backend
Commit migrated from https://github.com/dotnet/corefx/commit/9d4347b5bdca817937dea602f452df3fc2e9e2f3
2016-03-23 16:42:05 -04:00
stephentoub e9e2575810 Change http shim to support getting better version info
Currently the shim exposes a single method to get just the information that was needed when this was written.  Every time we need to get additional version info, we need to change the existing signature (which won't version well) or add additional similar signatures (will which be confusing).  Instead, I've changed it to have more fine-grained entrypoints, each exposing a particular piece of info.  We may end up making a few more interop calls on first-use, but the overhead is negligable.

With that scheme, I've then exposed additional entrypoints for getting version information, in order to provide better tracing and exception error messages.

This is then also used in tests to only run tests when certain features are available.


Commit migrated from https://github.com/dotnet/corefx/commit/29b0dc7b810776178bf42851064c397e47c4d0b8
2016-03-23 14:10:36 -04:00
stephentoub 436bbdf105 Add HttpClientHandler tests for server certificates
Commit migrated from https://github.com/dotnet/corefx/commit/65a4486bfe44c633c2e4dad6dabc6688bea16cc2
2016-03-23 14:10:19 -04:00
stephentoub 3495cb91d4 Fix SSL settings when server callback registered
Setting VERIFYPEER to 0 not only tells libcurl/OpenSSL not to do verification of the peer, but also to ignore any failures from our callback.

Also add a check for revocation checking and throw a PNSE if the backend doesn't support us registering the necessary callback.


Commit migrated from https://github.com/dotnet/corefx/commit/e3a4845289edf4ffa3f4da41efff52e3f6363c6c
2016-03-23 14:09:44 -04:00
stephentoub 0de8ee2b33 Update packages to rc3-23923
Commit migrated from https://github.com/dotnet/corefx/commit/123180cde4aadbed151ffbc00c09b85b7532da68
2016-03-23 11:56:57 -04:00
Eric StJohn 02af87b7e8 Merge pull request dotnet/corefx#7014 from ericstj/xamarinAsFrameworkReference
Add-ref 1:1 assemblies on Xamarin

Commit migrated from https://github.com/dotnet/corefx/commit/181e6331d98acbf976ace048c63101feec0f612f
2016-03-22 11:33:27 -07:00
Eric St. John db01546613 Temporarily revert implementation assembly version to match package version
I made a previous change to decrement assembly versions to enable our packages to be consumed
in desktop and redistribute netcore50 assemblies: https://github.com/dotnet/corefx/pull/6902

That caused a lot of runtime breaks because folks who were built against old packages would
get ref-def mismatches at runtime.  Rather than keep everything broken until the whole stack
updates I'm moving the implementation assemblies back to the old versions.  This will let folks
move to the new packages with the lower versioned ref-assemblies.  Once everyone is on the new
packages we can undo this change.

Change is going directly into TFS to make tonight's build.  I will deal with the fallout during mirror.

[tfs-changeset: 1588328]


Commit migrated from https://github.com/dotnet/corefx/commit/0f268ed1079c182d71cdf49cde3f339a01d67863
2016-03-22 06:47:57 -07:00
Stephen Toub 3ffda29b90 Merge pull request dotnet/corefx#7060 from stephentoub/curl_certs
Implement several certificate properties on CurlHandler

Commit migrated from https://github.com/dotnet/corefx/commit/42857d83882be72db269c14d83345f9a5e740cb6
2016-03-21 16:20:43 -04:00
stephentoub 5c548a386c Address PR feedback, and misc cert-related improvements
- Disable libcurl's cert verification when we're going to do it all ourselves
- Disable application policy for the single-cert manual case
- Avoid allocating a List when a simple array suffices
- Avoid an array allocation when a stack handle is invalid
- Dispose of a chain when Build fails in client callback
- Dispose of chain and certificate in client callback
- Avoid explicitly throwing an exception across an interop boundary when an invalid SSL pointer is provided
- Use named return constants in client callback for readability
- Dispose of certificates retrieved from store
- Remove some unnecessary code in GetRequestCertificateAuthorities


Commit migrated from https://github.com/dotnet/corefx/commit/027eb1e0dbac9bfa1c9b925fcf84e0566372d916
2016-03-21 12:44:20 -04:00
stephentoub 7754902596 Implement several certificate properties on CurlHandler
Adds implementations for:
- ClientCertificates
- ServerCertificateValidationCallback
- CheckCertificateRevocationList

I've explicitly not added these to the contract, as we're not ready for that yet on other platforms, and I've not added tests (though I've done some testing manually, such as verifying that I could run tweaked versions of the WinHttp server callback tests against this successfully).


Commit migrated from https://github.com/dotnet/corefx/commit/8376a43a5c425cc78dfb94c53b6f100eb5146aca
2016-03-21 12:44:19 -04:00
stephentoub b60997fa74 Update packages to rc3-23921
Commit migrated from https://github.com/dotnet/corefx/commit/3eb508d41d476e4ca0c74d106584c7a7f0d51a17
2016-03-21 12:10:10 -04:00
Jon Hanna 1c58a2a42a Fix multiple typos [5]
Commit migrated from https://github.com/dotnet/corefx/commit/00a0871c5cc4ff6af7f036946eef48644ed1e27d
2016-03-20 19:15:44 +00:00
Eric St. John 6aeccb0bae Fix tests to restore using the latest packages
We removed the lifting from the lineup so tests should reference the
latest packages in order to ensure an implementation is available.

The latest pacakges exclude implementation dependencies so I needed to
add these to projects that were depending on them coming in transitively.


Commit migrated from https://github.com/dotnet/corefx/commit/bef9061fd1238adf47b864d8924d121e4134465b
2016-03-19 08:01:11 -07:00
Eric St. John d28646e6b3 Fix restore errors in source projects
The latest drop of packages no longer includes lifting entries in the
lineup.  This causes errors when restoring for a concrete TFM and no
implementation assembly is in the packages.

I addressed this issue two ways:
1. In places where we were targeting a concrete TFM but packaging as
 NETStandard, just target NETStandard instead.
2. In places where we were targeting a concrete TFM but that packages
were missing the implementation on that TFM, update the reference to
newer package version where implementation is available.


Commit migrated from https://github.com/dotnet/corefx/commit/dfb30176c6056f5b3427515c4444a9dc31b9ba4f
2016-03-19 08:01:10 -07:00
Eric St. John ff75367f93 Update packages to rc3-23918
Commit migrated from https://github.com/dotnet/corefx/commit/d3d217b2ab336b862c27a3e605e32dc0c0a6d472
2016-03-19 08:01:09 -07:00
Kevin Jones c428584581 Fix typo in file name.
Commit migrated from https://github.com/dotnet/corefx/commit/af8c01f507c9227a8a11fb752c7df2142f7b4044
2016-03-18 12:45:24 -04:00
Eric St. John 1586e36fed Add-ref 1:1 assemblies on Xamarin
Microsoft.CSharp, System.IO.Compression, and System.Net.Http are all
reference assemblies in the desktop and mono/xamarin targeting packs.
As such these won't be referenced automatically.  Ensure we add a
reference when installing the package.


Commit migrated from https://github.com/dotnet/corefx/commit/eedef71bc2f4fe040ce10a5a59d385b036d3375f
2016-03-17 17:20:57 -07:00
stephentoub 1cbe15bf38 Query for the right proxy creds in HttpClient
Both the WinHttp and libcurl implementations are using the target Uri to lookup the right proxy credentials rather than using the proxy's Uri.


Commit migrated from https://github.com/dotnet/corefx/commit/d0cc5116a9906834f5ebd1813c9b9eed68ea054b
2016-03-17 10:34:06 -04:00
Eric St. John b134ef2308 Ensure stable assembly ref versions.
Make sure that all of the projects that consume API versions
decremented by
https://github.com/dotnet/corefx/pull/6902/commits/dotnet/corefx@716bb82ed9eb75a5a1e9beb0472d403177cff53f
reference the decremented assembly version.


Commit migrated from https://github.com/dotnet/corefx/commit/fe5b65ef7eaf4ede18e6bf47fc0bbdd79402b5b5
2016-03-15 13:57:09 -07:00
Eric St. John 7600be1e8b Make desktop inbox contracts match inbox version
Fixes https://github.com/dotnet/corefx/issues/5842

For API assemblies that are inbox in desktop and have no API changes
over the version in desktop, don't increment revision.


Commit migrated from https://github.com/dotnet/corefx/commit/6ad2e34491d3cd3a078c225f98b2c49268db81e1
2016-03-15 13:57:04 -07:00
Justin Van Patten 34d430921b HttpClient: Add comment to Set-Cookie test
Add a comment explaining the header value lengths being tested.


Commit migrated from https://github.com/dotnet/corefx/commit/2664968783439ddc3b64b99e0d42d1d293e1a082
2016-03-12 09:07:03 -08:00
David Shulman a576f9d8e1 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/ad0aa0c7f912a39275c955062e805d8853993f31
2016-03-11 07:07:20 -08:00
David Shulman 420449a472 Fix WinHttpHandler when no proxy creds after 407 response
We were getting an assert if we had an authenticating proxy but didn't have any credentials to send. After the initial 407 was received from the proxy, we then tried to set credentials for a retry. But since we didn't have any, we triggered an assert in SetWinHttpCredential.

The fix is to check for null credentials after getting the 407 response. If there are no credentials, then we end the retry loop with the final 407 status code.


Commit migrated from https://github.com/dotnet/corefx/commit/89966ef37a1269471069c2ee14cdb6af51d8a707
2016-03-10 19:18:38 -08:00