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
* 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
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
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
This change sets up the layout for having multiple test projects for Http. It follows the current guidlines as well as working within the BUILDTOOLS requirements of having ".Tests.csproj" for the names of the projects.
Commit migrated from https://github.com/dotnet/corefx/commit/e7b68608db14327ec55fc90c0f5aee3ed72fab36