Commit Graph
88 Commits
Author SHA1 Message Date
stephentoub 77c4c79e77 Respect CancellationToken provided to ReadAsync
In the previous commit, we only polled the user-provided CancellationToken prior to waiting on the synchronization primitive, but the sync primitive wait was only cancelable by shutting down the stream.  This commit updates that logic to support also canceling the asynchronous wait via the user-provided CancellationToken.


Commit migrated from https://github.com/dotnet/corefx/commit/80d2b157525211b655c3f81dde0ace6be9617720
2015-09-02 23:44:56 -04:00
stephentoub c129d77277 Implement ReadAsync on CurlHandler response stream
Today, CurlHandler provides a response content stream that doesn't override ReadAsync.  As such, any consumers reading data using ReadAsync will actually end up blocking a thread pool thread doing a synchronous Read.

This commit fixes that by implementing ReadAsync to be truly asynchronous.  If data is already available, a task is returned immediately.  Otherwise, the reader asynchronously waits for the writer to publish data and then consumes that data.

The overall design of the response stream remains the same as it was.  However, there are some notable changes:
- A SemaphoreSlim is now used instead of a ManualResetEventSlim for the _writerPublishedDataEvent.  This was done because SemaphoreSlim supports both synchronous and asynchronous waiting.
- The _readerRequestingDataEvent was removed, as it was no longer necessary.
- We no longer allocate an UnmanagedMemoryStream per write operation, instead simply storing the IntPtr buffer and long length on the response stream.
- Additional reorganization was done, primarily to share logic between Read and ReadAsync.


Commit migrated from https://github.com/dotnet/corefx/commit/c2af3efe7356efa34887c144940c2c1e6f60271a
2015-09-02 23:33:47 -04:00
stephentoub 513897b947 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/1180bfb82845bf10b9131785d02352513f59733e
2015-09-02 09:37:47 -04:00
stephentoub b846895de0 Refactor CurlHandler for threading and resource cleanup
This change overhauls how CurlHandler manages its threading and resources.

CurlHandler is now split into three types:
- CurlHandler, which represents the shell of the handler, contains some helper functions, and contains a "MultiAgent".  It submits "EasyRequest"s to the "MultiAgent".
- CurlHandler.EasyRequest, which represents all of the state associated with a SendAsync request on the HttpClient.
- CurlHandler.MultiAgent, which represents the owner of a libcurl multi handle and all of the processing associated with it.  The MultiAgent is responsible for actually processing EasyRequests, which CurlHandler queues to it.

MultiAgent is designed to not require any cleanup.  When the first EasyRequest arrives, it spins up a worker that creates a multi handle to process the request.  Any additional requests to arrive while that worker is active will be processed by that worker and multi handle.  When no work remains, the multi handle and the worker goes away.  If/when another request arrives, a new multi handle / worker are spun up.  Etc.

Almost all of the locking previously there was removed, as the worker thread is now solely responsible for doing all work on the multi handle.  The only locking now is when the CurlHandler hands off an EasyRequest to the MultiAgent, it needs to lock to store the request into the agent's queue, and the MultiAgent needs to lock to access it.

This design avoids threading issues we faced with regards to accessing state managed by the multi handle without holding the lock (e.g. polling file descriptors) and avoids having multiple threads blocked waiting on the lock to do processing associated with the multi handle.  It also makes resource cleanup easy: all state associated with the easy handle is cleaned up when that thread is done processing the easy handle, and all state associated with the multi handle is cleaned up when the worker thread shuts down.

The change also ensures that we always complete the response message, and that any exceptions that occur are propagated as needed to Read on the response stream.

And the design will make it trivial in the future to change the relationship between a CurlHandler and a MultiAgent:
- If we want one MultiAgent shared across all CurlHandlers, we just change the _agent field to be static instead of instance.
- If we want a pool of MultiAgents, we can simply create a collection of them and round-robin between them from one or more CurlHandlers.
- Etc.

All of the configuration code remains, e.g. what options are set on the easy and multi handles, but the code has been refactored.  I also include CURLOPT_NOSIGNAL to avoid multithreading problems per the docs.

Along the way, I cleaned up some stale interop that's gotten left behind through various iterations, and I fixed a few small issues related to behavioral differences from Windows, e.g. CookieContainer never returning null, UseCookies defaulting to true, etc.


Commit migrated from https://github.com/dotnet/corefx/commit/b7e7847677236ca0afd0b400bd1fcc138d960902
2015-09-01 21:45:32 -04:00
Hemanth Kapila 1b11b28b8f Introducing tests for HttpClientHandler
This checkin tests the client handler in following scenarios:
* Http and Https calls
* Authentication
* Redirection
* Redirection + Authentication
* custom headers
* cookies


Commit migrated from https://github.com/dotnet/corefx/commit/5040201f90c169d6033532170547f111a28bfb81
2015-09-01 16:42:27 -04:00
bartonjs 239b7928ea Split libcurl Interop files into smaller pieces
Commit migrated from https://github.com/dotnet/corefx/commit/97c488939ef8f9b114b9b263e8cb84e5f7a6d54a
2015-08-28 00:32:43 -07:00
Nick Guerrera a82a81a5d4 Add System.Net.Http.Native shim and seed it with curl initialization
Commit migrated from https://github.com/dotnet/corefx/commit/1448599198ed0f14bc87c6e96c44c5e9622e4b06
2015-08-27 22:25:50 -07:00
Stephen Toub 6475c96805 Merge pull request dotnet/corefx#2944 from vijaykota/feature
Fix an assert in CurlHandler multi handle release path

Commit migrated from https://github.com/dotnet/corefx/commit/bbcaaafc98a678a742bebe9975239a17a7e27f42
2015-08-27 11:21:54 -04:00
Vijay Kota f96c9aa041 Incorporate PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/6e0e365a2437a00046c223244305d8156d47c9d4
2015-08-27 18:11:35 +05:30
Vijay Kota 3c59373235 Take ref on multi handle to prevent race with Finalize
- Also fix leaks and task completion order for BeginRequest errors/cancellations


Commit migrated from https://github.com/dotnet/corefx/commit/88b69e5d9a3e233b47ea74e3418c77714a9f7b29
2015-08-27 16:23:03 +05:30
Stephen Toub 66c1944af1 Merge pull request dotnet/corefx#2974 from nguerrera/shim-pipe
Shim pipe and fcntl

Commit migrated from https://github.com/dotnet/corefx/commit/86d077fb5f283d719c6502a78df88e3c7b63f72a
2015-08-26 22:38:07 -04:00
Nick Guerrera 967ad34de3 Shim pipe and fcntl
Commit migrated from https://github.com/dotnet/corefx/commit/73502c91a21fbf4f4732cb89a386d8bd7f863c41
2015-08-26 13:39:17 -07:00
David Shulman 54525a2a94 Fix HttpClientHandler timeouts
Since HttpClientHandler doesn't expose all the timeout used by the
underlying WinHttpHandler, we need to disable those timeouts in favor of
the HttpClient.Timeout property.

Addresses issue dotnet/corefx#2857.


Commit migrated from https://github.com/dotnet/corefx/commit/86e89f73a1e7bf5b4fd40878f4fec4741a8651ca
2015-08-26 10:15:34 -07:00
Vijay Kota 03ad9e78bb Cleanup curl handles before marking task completion
Commit migrated from https://github.com/dotnet/corefx/commit/99c911b0ad702b9c433768d5d2b35ee0186ec0ca
2015-08-25 17:12:50 +05:30
Justin Van Patten 0d0c85067b Avoid unnecessary byte[] allocations in HttpContent
HttpContent.ReadAsStringAsync() has a bunch of calls to
Encoding.GetPreamble() as part of its encoding detection.
GetPreamble() creates a new byte[] each time it is called.
These byte[] allocations can be avoided. Also, as part of this,
cleaned up and improved the performance of the encoding detection.


Commit migrated from https://github.com/dotnet/corefx/commit/de05c8642746842f61cb063c3d43976f7ee00540
2015-08-25 01:04:38 -07:00
David Shulman 33efd55100 Merge pull request dotnet/corefx#2467 from justinvp/http_objectcollection
Avoid internal enumerator allocations in HttpClient

Commit migrated from https://github.com/dotnet/corefx/commit/7b2ed730d8326866a5649b94332c7edd8886cc61
2015-08-24 13:41:17 -07:00
David Shulman 1d920aad29 Merge pull request dotnet/corefx#2561 from justinvp/httpmethod
Optimize HttpMethod.GetHashCode()

Commit migrated from https://github.com/dotnet/corefx/commit/e296c69314d06af2bc6f8e8fea711a374cb1deab
2015-08-24 10:19:37 -07:00
Vijay Kota 9824cf29ca Fix an assert in CurlHandler multi handle release path
- If a timeout happens, the socket fd is not removed from _fdSet. When
  SafeCurlMultiHandle is finalized, it checks if _fdSet is empty and
  this assertion was failing. So ensuring that all codepaths of
  EndRequest result in cleanup from _fdSet


Commit migrated from https://github.com/dotnet/corefx/commit/bf40c3f442a59616f03871057633344d9230d4b6
2015-08-24 14:45:35 +05:30
Vijay Kota 7541da1388 HttpClient xplat: Fix bugs in polling and callback logic
- On OSX, the read end of the pipe sometimes wakes up the poll
  with a POLLOUT. Since we are interested in only reading on it,
  scoping down to POLLIN prevents this from happening. Else we
  attempt a read on it which fails

- CheckForCompletedTransfers was being unnecessarily called from the
  socket callback. We are only interested in MSG_DONE after the socket
  callback indicates removal. This will anyway wake up PollFunction which
  calls CheckForCompletedTransfers. This race is also causing a seg fault
  sometimes because curl_multi_socket_action has been called on an fd
  that was getting cleaned up via curl_easy_cleanup (call sequence is
  CurlSocketCallback --> CheckForCompletedTransfers --> EndRequest)

- Also removed some unnecessary CharSet attributes

cc: @stephentoub @davidsh @CIPop @SidharthNabar @pgavlin


Commit migrated from https://github.com/dotnet/corefx/commit/58178ce07fdf0e478467a77698c58fb6d1b4e866
2015-08-21 14:36:37 +05:30
Rajan Singh 680c39d776 Merge pull request dotnet/corefx#2810 from rajansingh10/myfeature
Moving shared default between winHttp & Unix Handler to a seperate common file

Commit migrated from https://github.com/dotnet/corefx/commit/e2e6dcc236c0c01463a1a43349be14761eabf442
2015-08-21 12:03:44 +05:30
Nick Guerrera e9ec7c9939 Merge pull request dotnet/corefx#2901 from nguerrera/shim-open
Use shims for open, close, unlink, shm_open, shm_unlink 

Commit migrated from https://github.com/dotnet/corefx/commit/b6dda6a964dbdd35ef40b8a285222ec4c7838464
2015-08-20 17:38:56 -07:00
Nick Guerrera 16d140fd57 Use shims for open, close, unlink, shm_open, shm_unlink
Commit migrated from https://github.com/dotnet/corefx/commit/709afe1d4f6b2d5ca75a0565e4c24e16a5254ee7
2015-08-20 15:50:44 -07:00
Stephen Toub 1eb19cf4e1 Merge pull request dotnet/corefx#2903 from rajansingh10/bugfix
Removed DumpHeaders dependency & coded to avoid unnecessary splitting

Commit migrated from https://github.com/dotnet/corefx/commit/29d76d3619397f8a458d2281f92b752ab0daac77
2015-08-20 16:55:33 -04:00
Matt Ellis 498a1839d5 Use OSS System.Net.Http for TFS Builds.
Update the internal System.Net.Http for CoreCLR project to point at the open source version.

[tfs-changeset: 1516875]


Commit migrated from https://github.com/dotnet/corefx/commit/59220586485d8e11ed3f0db23cdc0231e7f338ba
2015-08-20 12:55:58 -07:00
Rajan Singh 1c8cff88c3 Removed DumpHeaders dependency & coded to avoid unnecessary splitting
modified:   System/Net/Http/Unix/CurlHandler.cs


Commit migrated from https://github.com/dotnet/corefx/commit/3b43fdf172980df015d26c5712c5e825a7466d86
2015-08-21 00:19:38 +05:30
Stephen Toub 801539eb8e Merge pull request dotnet/corefx#2840 from shrutigarg/latest
Enabling POST method options

Commit migrated from https://github.com/dotnet/corefx/commit/18ccd5333e9fa19a8227b6dac54f2955a4962b52
2015-08-19 08:03:04 -04:00
Vijay Kota 0a710c583d HttpClient xplat: Fix multiple issues with socket/timer callbacks
In earlier version, a curl_multi_socket_action was performed everytime
the callback was invoked irrespective of whether there was activity on
the socket. This in turn causes more callbacks when libcurl tries to read
the socket but finds no data. This can be made more efficient by waiting
for activity on the socket and informing libcurl accordingly
- Fixed implementation of timer callback using an actual timer and handling
  all possible values of timeout
- Fixed a bug in CheckForCompletedTransfers where a mismatch could occur
  between the easy handle specified in the DONE msg
- Fixed the SEGV which was happening in earlier code due to recursive calls
  to curl_multi_socket_action in the socket callback which was being invoked
  synchronously in curl_multi_socket_action. This was causing a stack overflow
  leading to a segfault


Commit migrated from https://github.com/dotnet/corefx/commit/d52dcd394fc174db629acd771d8529714e4dc4f4
2015-08-19 10:21:25 +05:30
Hemanth Kapila 6c8af281b6 Credential Support in Unix HTTP Handler
This checkin integrates CurlHandler to the credential support of libcurl


Commit migrated from https://github.com/dotnet/corefx/commit/2c32a92fa672f84c9b4d2b8cf42a4543b498de80
2015-08-17 19:16:47 +05:30
Rajan Singh 43f0db204a Fixed build break
Commit migrated from https://github.com/dotnet/corefx/commit/3c576656325611b3a36c8fec777453be438133e7
2015-08-17 17:47:53 +05:30
Shruti Garg ff4acf7cce Enabling POST method options
Commit migrated from https://github.com/dotnet/corefx/commit/bb5e32a99dfd1ee7bf3c471a2b6f4c74528b61a5
2015-08-17 16:54:32 +05:30
Rajan Singh 9b679bfb53 Moving shared default between winHttp & Unix Handler to a seperate common file
Commit migrated from https://github.com/dotnet/corefx/commit/756ed1131ced4649c6a23940b9707012ec1d2ff2
2015-08-17 13:03:42 +05:30
stephentoub ba8bda425b Merge remote-tracking branch 'upstream/master' into from-tfs
Conflicts:
	src/System.IO.Pipes/tests/System.IO.Pipes.Tests.csproj
	src/System.Threading.Tasks/tests/project.lock.json


Commit migrated from https://github.com/dotnet/corefx/commit/c99aa51bff90dda680eb24a16998e5c99e29ba94
2015-08-14 22:43:59 -04:00
Eric St. John d7a0ae297b Update corefx packages to latest
Commit migrated from https://github.com/dotnet/corefx/commit/23f0b695bd162e0f665427c95180dc21931e5c70
2015-08-14 15:43:23 -07:00
Eric St. John 24877d3ce7 Move System.Net tests up to latest pre-release version
This change undoes the workaround from https://github.com/dotnet/corefx/commit/dotnet/corefx@5d9f9d4c6ea450366c7b70af6e6006a401284d14#diff-53766f09e26c8b4b422d2946d05c83a6


Commit migrated from https://github.com/dotnet/corefx/commit/ccdf7bb4a2a87de13f8dba69ac7a0df3818c69b1
2015-08-14 10:21:53 -07:00
Hemanth Kapila 643c412a2a PR Comments
Following PR comments were addressed:
*. curl_version_info_data is defined till the required field
*. the fields were made readonly.


Commit migrated from https://github.com/dotnet/corefx/commit/8f52c16490967b7906800a46bdea546cbfb526e8
2015-08-14 21:40:42 +05:30
Hemanth Kapila 91e60241d2 Introducing checks for libcurl features
Runtime and load-time checks to ensure that the features user is relying
on are available in the libcurl library loaded


Commit migrated from https://github.com/dotnet/corefx/commit/20eea4848cac8d8075eacef6dec12b750ca790d2
2015-08-14 16:52:09 +05:30
Eric St. John 77309d4821 Update the version of all assemblies
This change updates the assembly versions of all of the corefx assemblies
as needed after we shipped stable versions.  Assemblies with API differences
get a minor version bump.  Assemblies with only bugfixes get a build version
bump.

In order to facilitate this I had to update the reference assemblies, so I took
the opportunity to port them all to the open.

[tfs-changeset: 1514419]


Commit migrated from https://github.com/dotnet/corefx/commit/40723b795917f2e98b64d45c17effb2546dd0cae
2015-08-13 17:07:57 -07:00
Rajan Singh e80304b9a3 Enabled max redirection in HTTP xplat
modified:   ../../Common/src/Interop/Unix/libcurl/Interop.libcurl_types.cs
	modified:   System/Net/Http/Unix/CurlHandler.cs
	modified:   System/Net/Http/Unix/HttpClientHandler.Unix.cs


Commit migrated from https://github.com/dotnet/corefx/commit/868da12eee3983ad1fdf2031a99e68652b81addb
2015-08-13 21:45:28 +05:30
Rajan Singh 57f897f9e9 Incorporated comments
modified:   System/Net/Http/Unix/CurlHandler.cs
	modified:   System/Net/Http/Unix/HttpClientHandler.Unix.cs


Commit migrated from https://github.com/dotnet/corefx/commit/b2de38156bdd23e6cc3c3e5e40a30cac674475ca
2015-08-13 09:43:54 +05:30
Rajan Singh 81d1b7c09e Enabling cookie container in HTTP xplat
modified:   ../../Common/src/Interop/Unix/libcurl/Interop.libcurl_types.cs
	modified:   System/Net/Http/Unix/CurlHandler.cs
	modified:   System/Net/Http/Unix/HttpClientHandler.Unix.cs


Commit migrated from https://github.com/dotnet/corefx/commit/f79c1cd2a4c646b0434782c64f6de3a686b0bf38
2015-08-12 23:16:08 +05:30
Guillermo Rangel ff81931a13 Fixing CancellationToken not propagating properly and adding some Tests to verify it.
Addressing Feedback in GitHub

Renaming TestHandler to SendAsyncWinHttpMockHandler and adding missing spaces.

Added missing line in json file to use System.Runtime.InteropServices.RuntimeInformation.


Commit migrated from https://github.com/dotnet/corefx/commit/e76774df88b497107e8289fce314ea149abc7811
2015-08-11 13:58:39 -07:00
Vijay Kota b05f4378f9 HttpClient xplat: Add chunked mode support
Commit migrated from https://github.com/dotnet/corefx/commit/d3a3da65c8caf151adfd6db242676b0d6f275f35
2015-08-11 10:23:41 +05:30
Rajan Singh 0b27d483a6 Incorporated comments
modified:   System/Net/Http/Unix/CurlCallbacks.cs


Commit migrated from https://github.com/dotnet/corefx/commit/adfcc89dc3e4b59b0a615cfee3672ad5631751e3
2015-08-11 09:23:05 +05:30
Rajan Singh b29c787740 Incorporated Comments
modified:   System/Net/Http/Unix/CurlCallbacks.cs


Commit migrated from https://github.com/dotnet/corefx/commit/71bf1693fad49b2094a62d3afd69303977d4b977
2015-08-10 22:56:32 +05:30
Rajan Singh e24b5c3205 Fixing multi response header issue along with putting checks in http message parser
modified:   System/Net/Http/Unix/CurlCallbacks.cs


Commit migrated from https://github.com/dotnet/corefx/commit/1c126349c7614823131e09bc0cf78d7e5031865a
2015-08-10 17:12:07 +05:30
Vijay Kota 93bf847b92 HttpClient xplat: Basic request and response processing
- Also addressed some of the comments in https://github.com/dotnet/corefx/issues/2555


Commit migrated from https://github.com/dotnet/corefx/commit/3c24f2ce60a425e10ee903b7d252654dc399a175
2015-08-10 09:57:53 +05:30
Stephen Toub 7cbc620960 Merge pull request dotnet/corefx#2676 from dotnet-bot/from-tfs
Merge changes from TFS

Commit migrated from https://github.com/dotnet/corefx/commit/bd93302de81126297995adcd8b9cc16f82046ce9
2015-08-07 07:38:11 -04:00
David Shulman 7ccf0c26e2 Bug 1188675:Project N Bug: .NET HttpClient can't do Authenticated POSTs due to limitations of System.IO.NetFxToWinRtStreamAdapter
This bug revolves around a design limitations of the System.Runtime.WindowsRuntime System.IO.NetFxToWinRtStreamAdapter. Due to the way that the adapter works, the Windows.Web.Http layer is unable to "rewind" data in order to re-send it to the server for POST requests. Resending request entity-body data to the server is frequently needed due to authentication challenges.

The nature of this bug has resulted in a few common scenarios being broken for UWP (Windows 10 Store) apps that use System.Net.HttpClient or System.Net.HttpWebRequest. Even for simple content like StringContent (which is already buffered and not a stream, per se), we are unable to POST the data since the code paths were always using the limited NetFxToWinRtStreamAdapter.

The fix for this bug is multi-layered. In general, we try to avoid using the NetFxToWinRtStreamAdapter for the POST scenarios. For content that is ByteArrayContent (or derived classes), the data is already "buffered". So, we don't need to send it as a stream. We also check if the data has been buffered via the developer calling LoadIntoBufferAsync() explicitly and send it as a buffer. Then, if the data is not buffered, we check the stream itself. If it already supports the WinRT Stream interfaces, then we don't need to use the adapter. So, third-party devs can create compatible, multi-interface (.NET and WinRT) stream content to be POSTed.

[tfs-changeset: 1511754]


Commit migrated from https://github.com/dotnet/corefx/commit/e298b31e1da3dea3c3fd78f5f713b4659136484e
2015-08-06 20:53:35 -07:00
Hemanth Kapila 442793b080 Automatic Content Decompression
Modified CurlHandler to set the curl options for automatic content
decompression.


Commit migrated from https://github.com/dotnet/corefx/commit/18aec3452bb7b6dea2190151f4f9a26fb7876401
2015-08-07 08:52:32 +05:30
Vijay Kota 46aeb59c0e Fix HTTPS checks in xplat HttpClient
Commit migrated from https://github.com/dotnet/corefx/commit/6a05a612275e9a2fef2aaba5e153c3604077b573
2015-08-05 10:03:08 +05:30