Commit Graph
407 Commits
Author SHA1 Message Date
stephentoub 716f5ee544 Fix ConnectTimeout_TimesOut_Throws test
This test wasn't actually running because it was incorrectly annotated as a [Theory] but without any data.  When changed to be a [Fact], it failed because the test depends on the Socket's listening backlog being filled so that a subsequent connect will time out, but Listen(1) doesn't actually force the OS to use a queue of max size of 1, its just advisory.  The fix is to flood the server with requests that don't get accepted, filling the listen queue.


Commit migrated from https://github.com/dotnet/corefx/commit/883a32630a21c83bb91735cebf1d87c76691bd7d
2016-04-12 13:55:55 -04:00
dotnet-bot 6883e89fc3 Updating CoreFX dependencies to rc3-24008-00
Commit migrated from https://github.com/dotnet/corefx/commit/30b74738cdac9c75a2dd165d339f206b1070f3cd
2016-04-08 06:40:37 +00:00
stephentoub 1ab13b9661 Address PR feedback
And some additional cleanup, including removing a Tuple allocation when starting a new worker and fixing up some Debug.Asserts to be more informative.


Commit migrated from https://github.com/dotnet/corefx/commit/274feb64c9e91539f4b5c912b762ae337e2eb7a5
2016-04-07 19:38:42 -04:00
stephentoub ea83470915 Improve reliability of CurlHandler MultiAgent worker
If something unexpectedly goes wrong in our worker loop, and in particular when queueing a replacement worker, we may end up leaving a request sitting in the request queue with no one to process it.  This commit ensures that if something does go horribly wrong, the agent is left in a state where subsequent incoming requests can still kick off another worker, and in the meantime any pending requests in the queue are failed, so that code blocking on them doesn't simply hang.

As I was looking at this and some of our dispose usage, I also cleaned up a few places that could be simplified using the C# 6 ?. syntax.


Commit migrated from https://github.com/dotnet/corefx/commit/ad4afcf61aa62aa85c26b2c058953fe18328ffd4
2016-04-07 17:28:16 -04:00
stephentoub b9c430844f Only call curl_multi_wait if there are active operations
The CurlHandler work is sometimes hitting brief pauses unnecessary, where it finishes processing the last active request and then calls curl_multi_wait to wait for more work to do.  This is purely wasteful and can be skipped when we know there aren't any more active operations.


Commit migrated from https://github.com/dotnet/corefx/commit/8075d3a1b54121b9f656e033fe6308de05eb7381
2016-04-07 17:28:16 -04:00
stephentoub 317c18111d Extend DNS cache timeout in CurlHandler
Now that we're allowing the multi handle to live for as long as the CurlHandler, the DNS cache timeout starts to matter much more.  libcurl will cache the results of DNS lookups, and by default will timeout entries after 1 minute.  Our Windows implementation defaults to 10 minutes, so I'm extending our Unix implementation to match that.


Commit migrated from https://github.com/dotnet/corefx/commit/184792734ebb89d95425e37c7d1631a84e05e624
2016-04-07 17:28:16 -04:00
stephentoub 8197041ce0 Match SafeCurlMultiHandle lifetime to its MultiAgent
Today each time we spin up a worker in CurlHandler, we create a new SafeCurlMultiHandle, use it for the lifetime of that worker, and then when the worker goes away, the multi handle is torn down. This was done for simplicity of resource management, but it also leads to significant overheads due to everything that libcurl caches associated with the multi handle, e.g. when the multi handle goes away, so does it connection cache, its DNS cache, etc.  This commit addresses that by extending the lifetime of the multi handle to match that of the CurlHandler.  We still lazily create the handle when the first worker is spun up, but then we keep it alive until the handler is disposed.  As before, we ensure that as long as a worker is running, the multi handle will be kept alive, even if the handler is disposed.


Commit migrated from https://github.com/dotnet/corefx/commit/8d911b76c2ba05eb1ef22cebd6fef5cad2a21893
2016-04-07 17:28:16 -04:00
dotnet-bot 0f0193e356 Updating CoreFX dependencies to rc3-24007-00
Commit migrated from https://github.com/dotnet/corefx/commit/d9fdf25de0e1cf35219a26d4f840302e5379f292
2016-04-07 05:37:12 +00:00
Stephen Toub d3980a698e Merge pull request dotnet/corefx#7523 from ellismg/run-tests
Remove "UnsupportedPlatforms" metadata

Commit migrated from https://github.com/dotnet/corefx/commit/0cdc8e39f80a749bfa25eb559ab014be4f7ec557
2016-04-06 09:21:15 -04:00
dotnet-bot be7ca463ae Updating CoreFX dependencies to rc3-24006-00
Commit migrated from https://github.com/dotnet/corefx/commit/aff79bf3fa8ce8c13b6084d82aca30e534142b81
2016-04-06 05:21:19 +00:00
Matt Ellis e631e1c680 Remove UnsupportedPlatforms metadata
Commit migrated from https://github.com/dotnet/corefx/commit/f5252c0c0d19622132e0edcf0b64783b798e3bbf
2016-04-05 14:38:52 -07:00
Matt Ellis 68e4373e9a Reconsile .builds and UnsupportedPlatform metadata
There were a handful of test projects that just didn't have .builds
files and some other cases where the data in the .builds file did not
match what was in the UnsupportedPlatforms metadata.

Some of the projects said the tests were unsupported on FreeBSD and
nowhere else. Given that these tests should most likely be supported on
FreeBSD (given that OSX and Linux both supported them), I've not moved
that logic into the .builds files.

If there ends up being a specific set of tests that the FreeBSD port
team wants to disable long term, they can add .builds metadata as they
see fit.


Commit migrated from https://github.com/dotnet/corefx/commit/836c6f12e1a05749d7d5bf27d02bd28f98eb76aa
2016-04-05 11:51:49 -07:00
stephentoub b559a6d703 Change ConnectTimeout default back to infinite
We'll keep it as infinite until we determine how this property is being exposed.  Otherwise, we're overriding the HttpClient.Timeout without giving a way to control it.


Commit migrated from https://github.com/dotnet/corefx/commit/dd3426f7b3cc4ef48b698c252acd16bec98f2e6f
2016-04-05 09:55:52 -04:00
stephentoub 8b16b341a4 Add CurlHandler.MaxResponseHeadersLength
Adds the MaxResponseHeadersLength property.


Commit migrated from https://github.com/dotnet/corefx/commit/8840bc7b3961cbaae547da068bd47d452a8a5dfe
2016-04-05 09:53:41 -04:00
Stephen Toub 7557aa945c Merge pull request dotnet/corefx#7510 from dotnet-bot/UpdateDependencies20160405051812
Updating CoreFX dependencies to rc3-24005-00

Commit migrated from https://github.com/dotnet/corefx/commit/92c2ebd01c926e4d63c27d2efbdc51b2141199e1
2016-04-05 07:43:33 -04:00
dotnet-bot 8c6d7acd5d Updating CoreFX dependencies to rc3-24005-00
Commit migrated from https://github.com/dotnet/corefx/commit/afbf526ac0fae250fc47623f2c43d2caa1abb803
2016-04-05 06:23:55 -04:00
stephentoub aba16573e8 Address PR feedback and fix test
Commit migrated from https://github.com/dotnet/corefx/commit/9854f2ac6fc75c67b4e414783a08067f8e2cd782
2016-04-04 22:30:28 -04:00
stephentoub bf66904b51 Add CurlHandler.MaxConnectionsPerServer option
Adds MaxConnectionsPerServer to CurlHandler.


Commit migrated from https://github.com/dotnet/corefx/commit/cf89034e4425fcd5bc4d00819e29c8c06a47d954
2016-04-04 22:18:07 -04:00
Stephen Toub 8f452c4b3c Merge pull request dotnet/corefx#7502 from dotnet-bot/UpdateDependencies20160404102117
Updating CoreFX dependencies to rc3-24004-00

Commit migrated from https://github.com/dotnet/corefx/commit/a2443bcbe3aa410007c1f1fc4f2c4394e5ce189e
2016-04-04 21:56:26 -04:00
Stephen Toub 44b8eb2705 Merge pull request dotnet/corefx#7462 from stephentoub/curl_contentlength
Fix CurlHandler Content-Length handling on redirects

Commit migrated from https://github.com/dotnet/corefx/commit/8992e73cf1bf09f93cd65ed2b0598c2508afa9e1
2016-04-04 20:23:12 -04:00
dotnet-bot 9f65b1e1ef Updating CoreFX dependencies to rc3-24004-00
Commit migrated from https://github.com/dotnet/corefx/commit/9fd2c8863f2be58ee5d1431f0c658de61e991551
2016-04-04 20:19:10 -04:00
Stephen Toub 4b74e9a08a Merge pull request dotnet/corefx#7503 from stephentoub/curlhandler_defaultproxycredentials
Add CurlHandler.DefaultProxyCredentials

Commit migrated from https://github.com/dotnet/corefx/commit/4bd8d0fcacce9a49a44c9b32022e892c109c7e15
2016-04-04 20:08:20 -04:00
stephentoub 15145110b1 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/d6ec5160a2112fcc0b28ceecc89b678c28b66ff8
2016-04-04 19:06:36 -04:00
stephentoub f44dff3e55 Fix CurlHandler Content-Length handling
CurlHandler was explicitly setting the Content-Length header, which overrides libcurl's default handling of Content-Length.  This means that  Content-Length was being sent even when it shouldn't have been, such as when redirecting a POST to a GET.  This commit changes how we handle Content-Length.  Rather than explicitly setting the header ourselves, we let libcurl do it, and we tell it the length of the input via the INFILESIZE and POSTFIELDSIZE options.

A few other issues addressed as well in the act of fixing this:
- A SafeHandle wasn't being disposed of in the case of a redirect.
- 301 wasn't being considered a redirect status code for the purposes of credential handling.
- Some code could have been a bit cleaner.


Commit migrated from https://github.com/dotnet/corefx/commit/864f0926754fbb781b81b543f972e069f6295a0c
2016-04-04 19:06:33 -04:00
stephentoub 73b6baf5db Address PR feedback and clean up formatting
Commit migrated from https://github.com/dotnet/corefx/commit/fb254e65f051f02192eaa62bc0fc0ea4f8259e3a
2016-04-04 18:45:54 -04:00
stephentoub 15ccbd065a Add CurlHandler.ConnectTimeout
Adds a timeout to the connection phase of CurlHandler.


Commit migrated from https://github.com/dotnet/corefx/commit/6880dca258fa33448983f6046b5b727ad1d56c27
2016-04-04 18:30:10 -04:00
stephentoub 63e8f36b90 Add CurlHandler.DefaultProxyCredentials
Commit migrated from https://github.com/dotnet/corefx/commit/256ecaf347b5e2b809722d1acbfb7bff1902bf06
2016-04-04 18:26:44 -04:00
Stephen Toub ba8bf6c2cd Add CurlHandlers.SslProtocols option
Add CurlHandlers.SslProtocols option

With libcurl on the OpenSSL backend (the recommended configuration), we can provide full-fidelity for this option.  With libcurl on another SSL backend, we can allow choosing all three TLS protcols or just one TLS protocol, but we can't support selecting two of the three.

Commit migrated from https://github.com/dotnet/corefx/commit/bd79e80f25923e0f2e29e07aba60b03070596bb4
2016-04-04 17:27:18 -04:00
Stephen Toub 979a030e2e Merge pull request dotnet/corefx#7494 from stephentoub/curlhandler_encodedproxycreds
Fix encoding of proxy credentials in CurlHandler

Commit migrated from https://github.com/dotnet/corefx/commit/30ac912cb2ee065192bb9c928aca74996d43546c
2016-04-04 17:26:14 -04:00
stephentoub 7f83f8ddc6 Fix encoding of proxy credentials in CurlHandler
We need to URL encode the username/password for a proxy.  Otherwise, for example, a colon in the name could mess up how the concatenated username and password are parsed.  libcurl URL decodes them.


Commit migrated from https://github.com/dotnet/corefx/commit/9b4f73c0e9b4e671a2d47a5b4f53e68a9d93240d
2016-04-04 15:54:12 -04:00
stephentoub 425957d45e Tweak SSL context callback in CurlHandler
- Perf.  We were creating a SafeHandle for the SSL context, but it didn't own the underlying handle, and we were then just passing it back to two native functions.  We can skip the SafeHandle altogether, saving on the allocation and marshaling costs for all SSL connections.
- Error handling.  For robustness, we should be ensuring that any problems related to getting the state from the GCHandle result in returning an error code rather than propagating an exception, which will likely crash.
- Naming.  The name of the callback method is no longer correct, as it's use for more than just cert verification.


Commit migrated from https://github.com/dotnet/corefx/commit/b736f46255000a40219f3c5be864782cdb450d59
2016-04-04 08:57:13 -04:00
James Ko 3c397e122e Use nameof in WinRT's HttpClientHandler
Commit migrated from https://github.com/dotnet/corefx/commit/2f767c97104e16790c618a950ac04895cef47c53
2016-04-03 10:52:14 -04:00
Stephen Toub be0ad5fb0d Remove stale TODO from CurlHandler
Based on decision in https://github.com/dotnet/corefx/issues/6408.

Commit migrated from https://github.com/dotnet/corefx/commit/aa35622312605b6872a0fb50ca2e4ee2c5bce9f0
2016-04-03 08:00:25 -04:00
stephentoub 0687204ddb Refactor HttpContent with async/await
Commit migrated from https://github.com/dotnet/corefx/commit/d44015edc83042c8b34b1cf051b9371753fdc528
2016-04-02 17:39:05 -04:00
Lakshmi Priya Sekar f452ecd1cd Fix project dependencies from the xunit extensions update.
Commit migrated from https://github.com/dotnet/corefx/commit/1939982be59ede355131c9d85684dba4b0449c50
2016-04-01 14:58:15 -07:00
Lakshmi Priya Sekar 2a3abf12b4 Update xunit.netcore.extensions to latest.
Commit migrated from https://github.com/dotnet/corefx/commit/a7bb9eb3327f5cc791d39b4cff764dd7dd29fda5
2016-04-01 14:04:56 -07:00
Stephen Toub 93152ee66a Merge pull request dotnet/corefx#7405 from stephentoub/getasync_tasks
Further reduce Task allocations in GetString/ByteArrayAsync

Commit migrated from https://github.com/dotnet/corefx/commit/43350da9750b3a7ce5e674aaf828a8c487cde7d9
2016-04-01 07:37:01 -04:00
stephentoub b6c4853a6b Further reduce Task allocations in GetString/ByteArrayAsync
The HttpContent ReadAsStringAsync and ReadAsByteArrayAsync methods ensure that the data is loaded into the buffer, via an async operation, and then process that buffer synchronously.  This refactors that synchronous processing into its own method, and changes ReadAs methods to use a simple async method that does the await on LoadIntoBufferAsync and then calls these methods.  This avoids any task-related allocations if the data is already buffered.  It also makes those synchronous methods callable from the GetString/ByteArrayAsync directly, such that these methods can avoid an extra layer of continuations, as they already do their own buffering.


Commit migrated from https://github.com/dotnet/corefx/commit/1334af155c3892a45e42505a85a1eaf194344572
2016-03-31 15:49:21 -04:00
Jonathan Miller 0e43cc624e Merge pull request dotnet/corefx#6572 from sokket/builds
Adding builds files to the test projects

Commit migrated from https://github.com/dotnet/corefx/commit/e8326c3dab65e2e8eac466f346a9693788d41ca9
2016-03-31 11:41:43 -07:00
Jonathan Miller 7c2ce6913c Adding builds files for the test projects
Commit migrated from https://github.com/dotnet/corefx/commit/752599494fce80b5d0059a9090fdc010d8c7f45b
2016-03-31 10:46:26 -07:00
David Shulman 7eb1b02cbe Merge pull request dotnet/corefx#7302 from stephentoub/streamtostreamcopy
Improve memory usage of HttpClient's StreamToStreamCopy

Commit migrated from https://github.com/dotnet/corefx/commit/1f43828ee4797aeb434c525eb036bde1f69a5e3c
2016-03-31 09:24:01 -07:00
Stephen Toub 695186abcb Merge pull request dotnet/corefx#7379 from stephentoub/multipart_async
Refactor MultipartContent to use async/await

Commit migrated from https://github.com/dotnet/corefx/commit/963a99a2250195cb772979b5a020ac53d0f2288c
2016-03-31 10:22:59 -04:00
stephentoub 025ea3f97f Update packages to rc3-23931-00
Commit migrated from https://github.com/dotnet/corefx/commit/e421dd9c41c308f83511e350c1e407d1f728ba78
2016-03-31 08:26:49 -04:00
stephentoub c891144523 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/0008d5c0a35483666f04a06d67c25f9f2c5c3ecc
2016-03-31 08:17:16 -04:00
stephentoub b3aefad684 Refactor MultipartContent to use async/await
Improves both code clarity and performance.


Commit migrated from https://github.com/dotnet/corefx/commit/1102890d828a46a865b32b09865b4527e0a93fa3
2016-03-30 23:22:28 -04:00
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