Commit Graph
130 Commits
Author SHA1 Message Date
stephentoub 613a87d035 Add explicit 0 index args to Array.Copy usage
Array.Copy is implemented to work with any System.Array, not just T[].  When Array.Copy(sourceArr, destArray, length) is used, it delegates to Copy(sourceArr, sourceIndex, destArray, destIndex, length), and as such needs to query for the lower-bound of the supplied arrays, since although a T[] in C# always has a lower-bound of 0, an arbitrary Array may not.  Given this, when calling Array.Copy, instead of calling Array.Copy(src, dest, length), it's slightly more efficient to just call Array.Copy(src, 0, dest, 0, length), avoiding the need for the GetLowerBound calls made while delegating to the 5-arg version.

I noticed one occurrence of this in some code I was looking at, and while fixing that, I fixed all of them across corefx\src.


Commit migrated from https://github.com/dotnet/corefx/commit/979026e435672e611e3f6e0647c873aa96ccc684
2015-10-02 13:56:48 -04:00
Ian Hays 0f8197a86c Update CoreFX to xunit 2.1.0
Commit migrated from https://github.com/dotnet/corefx/commit/87b48c58936d66fcb201b3a8ad0961fa055f23b9
2015-10-01 19:56:49 -07:00
Hemanth Kapila 4f26738d30 CURL Handler redirect fixes
This commit fixes the following issues  in CurlHandler w.r.t following URI redirection

* Ensure that the credentials are nullified at the right place. We should not set username and/or password to null unnecessarily. libcurl differentiates between unset UserNames/Passwords and null user names/passwords

* Ensure that libcurl follows only HTTPS uri if the original request was for a HTTPS URL.

* Ensure that libcurl follows only a HTTPS or a HTTP uri if the original request was for a HTTP URL.

* Ensure redirect results in a proper response code

* For all requests, limiting protocols to http and https


Commit migrated from https://github.com/dotnet/corefx/commit/7c59e04ce8b26887c386fc3045882196a3142b36
2015-10-01 19:34:28 +05:30
David Shulman faecfe5a93 Merge pull request dotnet/corefx#3554 from davidsh/more_http_tests
Add more HTTP tests

Commit migrated from https://github.com/dotnet/corefx/commit/1338765c9d6be95506edcdf2dab00f4c5d9153d2
2015-09-30 20:49:57 -07:00
David Shulman a6002ce802 Add more HTTP tests
* Add more tests ported from the internal ToF tests.
* Cleanup existing tests to be consistent in style and format as it has
drifted due to many different people working on the tests.
* Disposing the HttpClient object will dispose the handler as well so we
don't need multiple 'using' statements unless we are explicitly testing
dispose ordering semantics.


Commit migrated from https://github.com/dotnet/corefx/commit/ad55c1d5685afc4009cb2481fcc7c5e4f4a551f8
2015-09-30 20:11:07 -07:00
bartonjs a52f41057c Update all CoreFx package references to 23328 build.
`build.cmd /p:LockDependencies=true` was the start of this change, but some errors with xunit build numbers led to all xunit upgrades being reset back to what they had in master.

project.json changes:
* System.Net.Security\src Switch off of explicit beta versioning, use the same baseline as everyone else.  The S.S.C.Algorithms explicit upgrade is no longer required.
* System.Net.Requests\tests didn't build.  Looking at the project.lock.json change, it appeared that a System.Net.Http reference was lost, restored it.
* System.Net.Http\tests didn't build. Looking at the project.lock.json change, it appeared that a System.IO.FileSystem reference was lost, restored it.
* System.Net.WebSockets.Client\src didn't build. Looking at the project.lock.json change, it appeared that a System.Collections (4.0.10) reference was lost, restored it.
* System.Diagnostics.TextWriterTraceListener\tests needed the runtime reference to load the correct System.Diagnostics.TraceSource binary.


Commit migrated from https://github.com/dotnet/corefx/commit/cec3a0f2db542bfa9d9c56bf988d966eacc35ad9
2015-09-29 11:40:37 -07:00
Stephen Toub 02eb1e1b80 Merge pull request dotnet/corefx#3333 from stephentoub/fix_curl_assert
Remove faulty assert from CurlHandler.CurlResponseStream

Commit migrated from https://github.com/dotnet/corefx/commit/f92cf14f08e1636072b18ac3c46c697c6c390ed4
2015-09-22 09:30:28 -04:00
Hemanth Kapila e2dc229d7b Merge pull request dotnet/corefx#3328 from stephentoub/supportsredirectionconfig
Implement CurlHandler.SupportsRedirectConfiguration

Commit migrated from https://github.com/dotnet/corefx/commit/5a4eb8afb6393a37043ba82f5dbbbd9c3cc54151
2015-09-22 18:55:25 +05:30
Stephen Toub 4db6ddbde9 Merge pull request dotnet/corefx#3360 from Clockwork-Muse/System.Net.Http_ProjectFile
Correct broken System.Net.Http solution file.

Commit migrated from https://github.com/dotnet/corefx/commit/6f6c12c3be1cb6e6148bc05ea7e6cafaddd164ff
2015-09-22 08:30:00 -04:00
Hemanth Kapila dd0d1f999d Merge pull request dotnet/corefx#3307 from kapilash/use_default_creds
Allow UseDefaultCredentials property for HttpClientHandler on unix

Commit migrated from https://github.com/dotnet/corefx/commit/237b722c2035a5fd51e41b269a62b8df1286f945
2015-09-22 12:13:09 +05:30
Stephen A. Imhoff f01a8e122e Correct broken System.Net.Http solution file.
Commit migrated from https://github.com/dotnet/corefx/commit/039da4e1f033df584540736a3f9555b9383a3c95
2015-09-22 14:18:27 +09:00
David Shulman 9d997536f4 Port additional System.Net.Http tests to CoreFx
Added more http tests to open source from the original internal ToF tests. Some of
the tests should be refactored in the future to avoid Assert'ing multiple
logical things.

Fixed up test namespaces for System.Net.Http and
System.Net.Http.WinHttpHandler.


Commit migrated from https://github.com/dotnet/corefx/commit/e5a017cb6ca01e99b1f1462298bc0cbf60c06ee0
2015-09-21 11:48:34 -07:00
Christopher Costa cdfa624a04 XPlat packaging
Converts libraries to use platform specific implementations in packages.

[tfs-changeset: 1526941]


Commit migrated from https://github.com/dotnet/corefx/commit/b27061014ebd18d83031039f31721afa35d4612c
2015-09-20 11:57:30 -07:00
stephentoub 97c7401c5d Remove faulty assert from CurlHandler.CurlResponseStream
CurlResponseStream.VerifyInvariants has an assert that assumes that if the stream has been disposed, it must have also completed.  But since this stream is exposed publically, it's possible for consuming code to Dispose of the stream before the request has finished, violating the assert.  In such a situation, a subsequent attempt to transfer data to the response stream will fail and cause the request to be aborted as desired, cleaning up resources (there are probably some opportunities here for some optimizations to handle this case, but that can be explored later.)

This commit just removes the bad assert.


Commit migrated from https://github.com/dotnet/corefx/commit/cfc3f755af4302973d7455fdb86182822c467bdb
2015-09-20 10:26:14 -04:00
Hemanth Kapila 65ebeca3f6 HttpClientHandler.UseDefaultCredentials to be made a no-op
HttpClientHandler on windows securely uses logged-in user's credentials
when UseDefaultCredentials is set to True. This is achieved via winHttp.
Libcurl does not provide such functionality, so making this a no-op.


Commit migrated from https://github.com/dotnet/corefx/commit/60aa75f55e9149176a94e5ec5c3773688fcce5be
2015-09-20 12:25:44 +05:30
stephentoub 791179fdf2 Add MaxRequestContentBufferSize tests to lock in behavior
Commit migrated from https://github.com/dotnet/corefx/commit/e25c5020fd9e327dfdb7baffb9d772967b28abc9
2015-09-19 20:29:06 -04:00
stephentoub a22cd97af4 Implement CurlHandler.SupportsRedirectConfiguration
It does. Return true.


Commit migrated from https://github.com/dotnet/corefx/commit/d91900297d6430c6057abed2e513287d978fa8ec
2015-09-19 20:21:32 -04:00
stephentoub 0ba31ef907 Implement HttpClientHandler.MaxRequestContentBufferSize on Unix
Changed to match behavior on Windows (get returns 0, set throws PlatformNotSupportedException).


Commit migrated from https://github.com/dotnet/corefx/commit/dd7463ada578331d9b1ee5e25ee7e9998d6bf42a
2015-09-19 20:09:29 -04:00
Jonathan Miller fb3803dfe9 Finishing up PAL'ing Unix\libc (non-networking and crypto)
PInvoke calls


Commit migrated from https://github.com/dotnet/corefx/commit/f8fd4b7ff731cd8951e6da0bb70ca206533866bb
2015-09-17 13:05:29 -07:00
Wes Haggard a0d524ea1c Merge pull request dotnet/corefx#3177 from akoeplinger/update-dnx
Update build to use DNX beta7 instead of beta5

Commit migrated from https://github.com/dotnet/corefx/commit/34e8271eae1e8cbda5389f6b152c1f27994ca6c2
2015-09-16 10:34:50 -07:00
Stephen Toub 8dc75dfdc7 Merge pull request dotnet/corefx#3265 from nguerrera/shim-work
Increase native compilation warnings and fix the fallout

Commit migrated from https://github.com/dotnet/corefx/commit/77b35ab922586c69b51f4df66f3d8149f940e1a7
2015-09-16 13:15:56 -04:00
Nick Guerrera 23277810e6 Increase native compilation warnings and fix the fallout
We were using -Wall but now use -Weverything and opt out of only
a handful of issues such as C++-98 compat, which we don't need.

The most notable impact is that the compiler now catches
narrowing implicit conversions, which was also the primary
motivation for doing this now as there was known debt in our
unsupervised usage of 64-bit types for sizes.

We now assert on bad buffer sizes *and* retain full checks in
release builds to be completely defensive against overflow.

We now use int32_t for scratch buffer sizes. int64_t remains for
file offsets and uint64_t remains for memory mapped files, but
int32_t for scratch eliminates a bunch of managed casts and
therefore makes it easier to reason about overflow prevention.

INT32_MAX is also the most portable limit on these buffer sizes
because the behavior of functions like read is only implementation
defined when the input size is greater than SSIZE_MAX and ssize_t
is int32_t on the lowest common denominator of modern platforms.

Enums corresponding to platform values are now enum X : T instead
of enum class X : T. The PAL_* names are descriptive enough without
scoping and the implicit conversion to raw integer is actually helpful
to avoid a bunch of casts, which are otherwise needed to interop with
the corresponding native API.


Commit migrated from https://github.com/dotnet/corefx/commit/648c01d69fba8d23750122d9823f53257785c8ca
2015-09-16 09:15:33 -07:00
Hemanth Kapila 1cd1a63716 Redirect handling for cookies and creds
This fix realigns CurlHandler with WinHttpHandler w.r.t Redirect handling.
When redirect is detected, we clear the credentials if the credentials were originally provided as NetworkCredentials Otherwise we use the
forwarding URI to get the new set of credentials.
Like wise, in case of redirects, we get the cookies again from the cookieContainer

In addition, this commit also collects the cookies from the response header


Commit migrated from https://github.com/dotnet/corefx/commit/5d6c82b64c317a6e7e724778affb0f571acdcb2e
2015-09-16 09:39:48 +05:30
Alexander Köplinger 3e20a867b2 Update build to use DNX beta7 instead of beta5
The corefx build used an older beta5 version of DNX which hardcoded the path to bash in dnu, breaking the build on FreeBSD.
Updating DNX to the latest "stable" beta7 release fixes this.

After updating I noticed a few test projects didn't build anymore as they were missing some dependencies in project.json, added those.

Fixes dotnet/corefx#3173


Commit migrated from https://github.com/dotnet/corefx/commit/6df77fdbb6cf8e0d35a3074bb325f7810085daa3
2015-09-16 02:12:26 +02:00
Jonathan Miller 9e25edd8d1 Moving more Unix\libc function calls over to the PAL layer
along with fixing up the Interop calls for the switched
functions.


Commit migrated from https://github.com/dotnet/corefx/commit/aed4a23f36ace07e7f5f33bf5a28808fd215fea6
2015-09-11 14:09:37 -07:00
stephentoub b1d72f56c2 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/9f628cfa67e6c481b76c03aa8c9c50472df1863d
2015-09-10 08:40:32 -07:00
stephentoub 54c0b5401d Add tests for different request streams
Commit migrated from https://github.com/dotnet/corefx/commit/f9d1b3c47d4ff46afaa44fdb0eede63712e92164
2015-09-09 10:00:25 -07:00
stephentoub 4cf187c144 Ensure TransferEncodingChunked is set to true for non-seekable request streams
Commit migrated from https://github.com/dotnet/corefx/commit/cc1f2fe2f5743918960e72ec5e13c77fa7bca61b
2015-09-09 10:00:22 -07:00
stephentoub 680e45038b Avoid blocking CurlHandler in read callback
PR dotnet/corefx#3105 addressed the issue we were facing with libcurl and the write callback used when libcurl has response body data available.  We were blocking libcurl's callback until a reader was available to consume the data, resulting in both significant scalability issues as well as the potential for easy deadlock.  This was fixed by making the whole operation async via libcurl's ability to pause connections.

The same issue exists for libcurl's read callback, used by libcurl to read data from the request stream to send as part of the request.  The issue here isn't as impactful as on the write side, because a) a common case has no request stream or has a MemoryStream that serves up its data immediately, and b) other streams (e.g. FileStream) typically serve their data quickly even if blocking is involved and don't interact with the HttpClient in a way that could lead to deadlock.  However, it's still an issue, and it's still possible to construct cases where deadlock is possible, e.g. if the output stream of one request is used as the input stream of another request associated with the same libcurl multi handle.

This commit addresses the read callback case by relying on the same pause mechanism used for the write callback.  When libcurl requests data, if the source is a memory stream, we just do the read and hand back the data. Otherwise, we issue a ReadAsync on the stream.  If the operation completes immediately, we synchronously hand the data back to libcurl, storing any extra beyond what libcurl asked for.  If the operation didn't complete immediately, we store it for later, and pause the connection, requesting an unpause when the read operation completes.  Subsequent read requests from libcurl first try to be satisfied from any previous ReadAsync with
data remaining.

As part of this, I also removed the pause state tracking I'd previously added.  In my previous PR as part of adding support for pausing, I added a field to EasyRequest to attempt to mirror the current paused state as known by libcurl.  This was done to try to avoid requesting unpausing in cases where we'd like to be unpaused but have already requested it. However, this appears to have been premature optimization, as the case is relatively rare, the overheads relatively low for processing the extra request, and it causes additional headaches once we're able to pause sending/receiving individually.


Commit migrated from https://github.com/dotnet/corefx/commit/fbb6664ab924d82b536389822be1fe4c974f9f3c
2015-09-09 09:54:42 -07:00
Hemanth Kapila 5e333c2d1b Fix for dotnet/corefx#3124. CurlHandler sets invalid content-type for POST requests
libcurl defaults to a Content-Type:application/x-www-form-urlencoded for
Post operations. This default behavior is inconsistent with dotnet API.
Current PR fixes this issue by overriding the default value.
Also included is the test that was mentioned in dotnet/corefx#3124


Commit migrated from https://github.com/dotnet/corefx/commit/594ee48d91fbe827fb3e3cca05ef1cba8466e152
2015-09-09 11:56:39 +05:30
stephentoub 1add4894c1 Added EasyRequest ID and MultiAgent worker ID to verbose tracing
When multiple HttpClients are being used, and/or when multiple requests are being issued, this makes it possible to correlate the traced messages.


Commit migrated from https://github.com/dotnet/corefx/commit/7411902301fa9ee6528629c9a669bca9eea2026d
2015-09-07 12:21:49 -04:00
stephentoub e3f1aca0f4 Address PR feedback
- Changed properties on EasyRequest to be fields
- Changed CurlResponseStream to wrap an EasyRequest rather than a CurlResponseMessage
- Removed _position field that was only used for verbose tracing
- Added a few more VerboseTrace calls
- Changed _pendingReadRequest = null to ClearPendingReadRequest (not necessary, but good for consistency)
- Added another couple Debug.Asserts


Commit migrated from https://github.com/dotnet/corefx/commit/7ee7c7100ab70776546e78b2c84ef14519c4ffc5
2015-09-07 12:21:47 -04:00
stephentoub d25820bc15 Avoid blocking CurlHandler write callback
When receiving the body of an HTTP response, libcurl provides the data
received via a callback that's invoked synchronously from the thread
pumping libcurl's processing.  This callback can't return until it's
handed off all of the available data, and thus the current implementation
of CurlHandler blocks that thread until a reader has consumed the data.
This is both expensive and dangerous.  It's expensive because we end up
blocking a thread until some reader comes along, and it's dangerous
because this can easily lead to deadlock.  A libcurl multi handle may be
used by only one thread at a time, which means that if the handle is being
used by a thread while blocked on the write callback, no other thread can
access the multi handle, which means no other callbacks for other
concurrent requests can be invoked.  If multiple operations were queued,
and then the data for them arrived in an order that didn't exactly match
the order of readers consuming the data, deadlock would ensue.

This change makes it so that we no longer block the callback, taking
advantage of a pausing mechanism libcurl provides that allows one to pause
a connection until it's needed.

I rewrote the CurlResponseStream to manage this.  Now when the callback
has data to write, it attempts to transfer it to the stream.  If there's a
reader already waiting for the data (represented by a task stored on the
stream), the callback simply transfers its data to the reader.  If the
callback has too much data than would fit in the reader, the remaining
data is buffered on the stream.  If instead the callback finds that either
there isn't a waiting task or that there's already some remaining data
buffered from a previous callback, it instead pauses the connection, such
that no more callbacks will be invoked until we unpause.  From the reader
side, a reader who tries to read data from the stream can pull data from
the remaining buffer if there is any, or can register a task with the
stream that will be filled with data at some point when callback has data
available.

As part of debugging some issues with this change, I added a verbose
tracing mechanism that's enabled by compiling the library with the
CURLHANDLER_VERBOSE constant (the same that we use for enabling libcurl's
verbose diagnostic output).  I left the tracing in as I found it valuable
in diagnosing issues with the library, but we can remove it later if
desired.

I also added a test that deadlocks before the change and that completes
successfully after.


Commit migrated from https://github.com/dotnet/corefx/commit/308efaba2833e5e146319f74a2281e12ef3e5519
2015-09-07 12:21:45 -04:00
Shruti Garg 1d9af3015d Fixing Review comments Post/Put Testcases
Commit migrated from https://github.com/dotnet/corefx/commit/853100ed6f051b3af9eeee8b55e16a60a4703d1e
2015-09-07 12:40:27 +05:30
Shruti Garg ad0bf80977 Enabling Testcases for POST/PUT methods
Commit migrated from https://github.com/dotnet/corefx/commit/20b14c9e9948310a6f0eb507066411d5e7eab5ce
2015-09-04 15:49:23 +05:30
Alexander Köplinger 919950a89d Use SR.Format instead of string.Format
See https://github.com/dotnet/corefx/pull/3078.
This applies the same fix to all other places in the codebase.


Commit migrated from https://github.com/dotnet/corefx/commit/d2bb418da30f27f4ef4203f46f7bd3b57a9433a0
2015-09-04 00:03:05 +02:00
Stephen Toub 7aa0b6193b Merge pull request dotnet/corefx#3068 from stephentoub/http_read_async
Implement ReadAsync on CurlHandler response stream

Commit migrated from https://github.com/dotnet/corefx/commit/3c43c6b16a89184395af14713caedc286ce33168
2015-09-03 15:58:00 -04:00
stephentoub 3a858ba99e Address PR feedback
- Removed UnmanagedMemoryStream from project.json
- Added a few more Debug.Asserts


Commit migrated from https://github.com/dotnet/corefx/commit/0eb2ae72b959ba2d23e2f3edc8c25b7e7ec10d23
2015-09-03 14:46:39 -04:00
Hemanth Kapila aab1870a1e Incorporating PR feedback
Using named argument for isMulti


Commit migrated from https://github.com/dotnet/corefx/commit/1df6813990327ed57bb39e5ace92864379cc7b42
2015-09-03 22:38:35 +05:30
Hemanth Kapila 14f9bb4cd3 Fix for dotnet/corefx#3045. Fixing WebException.Status on Unix
This commit fixes dotnet/corefx#3045.
WebExecption class currently looks at the value of underlying HResult to
set the value of the Status.
We need to set the value of HttpRequestMessage.HResult to appropriate
CURLcode in case of errors. WebException maps this to the relevant
WebExceptionStatus


Commit migrated from https://github.com/dotnet/corefx/commit/7938b0df7624d35c0cff566e8c5a5f2475cefbe8
2015-09-03 21:30:31 +05:30
stephentoub b6606d5d29 Move good HttpClientHandler.Unix.cs file up one level
Now that the stale HttpClientHandler.Unix.cs file has been deleted, move the good one up to its location so that it sits next to its .Windows.cs counterpart.


Commit migrated from https://github.com/dotnet/corefx/commit/03377b795c99af0f0d4152382f34c5f471eeb7ab
2015-09-03 00:04:02 -04:00
stephentoub 77ff5253aa Delete stale HttpClientHandler.Unix.cs file
There are two HttpClientHandler.Unix.cs files checked in:
- One in System.Net.Http\src\System\Net\Http
- One in System.Net.Http\src\System\Net\Http\Unix

The former is the original stubbed out version, throws from every
property, and isn't referenced by the .csproj, whereas the latter is where
all of the recent development related to CurlHandler has happened.

This commit simply deletes the former from the repo.


Commit migrated from https://github.com/dotnet/corefx/commit/94ea117c8c558dfeae3327f089f820c0c0d4a487
2015-09-03 00:02:24 -04:00
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