Commit Graph
217 Commits
Author SHA1 Message Date
David Shulman d899bda510 Disable System.Net.Http tests on UAP/UAPAOT (dotnet/corefx#20017)
Disable a bunch of System.Net.Http tests on UAP/UAPAOT platform.

Both inner and outer loop tests now run clean for System.Net.Http

Commit migrated from https://github.com/dotnet/corefx/commit/38cd7f91dbbc5ac4001bf15762a8e244f5ec3a70
2017-05-19 14:28:54 -07:00
Jason Lin 996a786159 Enable most corefx tests for Bash on Windows
Many corefx tests are skipped when running on Bash on Windows. As of Win10 Creators Update, most of these skipped tests now pass, so they can now be enabled.


Commit migrated from https://github.com/dotnet/corefx/commit/cf3c7d5a3283da40e8a2849e8776e23c7292fb41
2017-05-14 21:02:27 -07:00
Stephen Toub 52d5beec99 Disable SendAsync_ReadFromSlowStreamingServer_PartialDataReturned test on netfx
This test sends some of the data planned by Content-Length but keeps the connection open; the client is then supposed to read that data and verifies that it got only what was sent and didn't hang.  But it's hanging on netfx.  The problem is that ConnectStream.BeginRead on netfx first reads what it has buffered, and if it doesn't have buffered as much as was asked for, it then issues an asynchronous read rather than just returning the what it has.


Commit migrated from https://github.com/dotnet/corefx/commit/2f19b380923cfeb8a7387d6c9cfad30a0b713f38
2017-05-10 15:06:43 -04:00
Stephen Toub 9401004824 Stop disposing of request content in HttpClient
HttpClient on Unix fails for some sites, in cases where the site sends a response before it’s fully received the entirety of the request.  That’s because HttpClient has logic to Dispose of the request content once the Task returned from the handler’s SendAsync completes, and unlike WinHTTP, libcurl doesn’t require that the whole request be sent before any of the response is processed.  That means that CurlHandler may receive the response (or the response headers), complete the SendAsync task, but still be reading from the request content, which may then be disposed of by HttpClient while it’s still in use, causing potential corruption, exceptions, etc.

The Dispose behavior has other problems with it.  A more generalized version of the above is that it prevents handlers that want to support full duplex communication, since it essentially requires that the whole request be sent before the response is processed.  It also forces extra cost onto consuming code in some situations, as it means that the request content objects can’t be pooled and reused (since disposal typically invalidates objects for such a purpose, though in some cases a custom content could be developed to override and ignore Dispose).

A variety of approaches were explored to address this:
- Change CurlHandler to only complete the SendAsync Task when both the request has been fully sent and the appropriate portion of the response has been received.  This is problematic, though, as with the pull model employed by libcurl, we don’t know reliably when the request has been fully sent.
- Change the disposal to be handled by the handlers rather than by HttpClient.  This could help in that a handler like CurlHandler could simply defer disposal until libcurl tells it the “easy” operation is done.  But it has other downsides. Today code can use an HttpClientHandler without HttpClient, e.g. by using HttpMessageInvoker instead of HttpClient, in which case it bypasses this disposal logic (and other logic provided by the relatively thin HttpClient wrapper). If we were to move the disposal logic to the HttpClientHandler, now such code that was never having its request content disposed will start to, which is bad and exactly the opposite of what we want. It also causes problems for chains of handlers, e.g. if HttpClient is given a handler that wraps CurlHandler, and that handler expects to be able to look at the request content after the SendAsync Task from CurlHandler completes but before it itself completes its SendAsync Task. And while such a scenario may seem far fetched, we effectively have it in the bits today: the diagnostic handler that's used to pass details off to DiagnosticListeners is injected in the middle like this, and it does pass off the request content after the wrapped SendAsync Task completes... if a listener was expecting a non-disposed request content at that point, it would be sorely disappointed.
- Simply stop disposing.  The primary downside here is existing code that may have expected disposal to happen, e.g. if a StreamContent wrapping a FileStream isn't explicitly disposed of by the app code, cleanup of the FileStream will be left to its finalizer.

The least bad option is to simply stop disposing.  This PR makes that change.


Commit migrated from https://github.com/dotnet/corefx/commit/6d06c39857f8bb7a798ca118944d25a43aaa8beb
2017-04-28 07:13:43 -04:00
David Shulman 3505e5abfd Root cause System.Net.Requests test failures on NETFX
Finished investigation of failures on .NET Framework for
System.Net.Http.

Added specific NETFX test changes where necessary. Opened up additional
bugs for investigation.

Added missing parameter validation for HttpClientHandler.MaxConnectionsPerServer
for the net46 OOB. This matches .NET Core now.

Removed some test code that was incorrectly trying to do CredentialCache.Add()
with a 'basic' authtype and using DefaultCredentials. This is invalid and
throws exception on netfx. Added dotnet/corefx#18870.

Remove PlatformNotSupportedProxy test code. It was throwing an exception
on netfx and the purpose of it didn't seem to make sense in the one test
that was using it.

Fixes dotnet/corefx#17691.


Commit migrated from https://github.com/dotnet/corefx/commit/b1246c7f1ee1d9e42594988073fd06580d23fe84
2017-04-24 14:09:31 -07:00
Viktor Hofer ebb1c635a9 Removed ActiveIssue comment in favor of explanation why this behavior is intended on Windows
Commit migrated from https://github.com/dotnet/corefx/commit/8fd9800cab67fe7eac59be441eadaec048234ed1
2017-04-15 13:49:27 +02:00
David Shulman fb0d9456d4 Adjust tests to check for proper Windows 10 update version
Remove unneeded old Windows 10 version check (IsWindows10VersionInsiderPreviewOrGreater).
Use the official Windows 10 Creators Update version number 1703 (build 15393) which is
already defined (IsWindows10Version1703OrGreater).

Fixes dotnet/corefx#8945, dotnet/corefx#10958


Commit migrated from https://github.com/dotnet/corefx/commit/d56c8d1185fdea71e0c210d8ab3d111a40dc3047
2017-04-04 13:04:59 -07:00
David Shulman 75d4e8ad18 Fixes for running Http tests against Desktop
Got the Http Functional tests running with no errors against NETFX (Desktop). Found a bunch
of compatibility differences between Desktop and Core that need to be investigated. For now,
the tests are skipped on Desktop.

Fixed the LoopbackServer so that it will run. It was blowing up with `MissingTypeException`
due to missing SocketTaskExtensions class (dotnet/corefx#17690).

Contributes to dotnet/corefx#17691


Commit migrated from https://github.com/dotnet/corefx/commit/b7f6f5f159ebe6c0597578bbd858697a6159a22f
2017-04-01 09:28:32 -07:00
David Shulman 5fd3a239ce Modify HttpClientHandler compression default to match Desktop
Change HttpClientHandler property for AutomaticDecompression to match
original .NET Framework default. Adjust tests accordingly.

Contributes to dotnet/corefx#17691


Commit migrated from https://github.com/dotnet/corefx/commit/eb21a724bff127d3ab0c34240234ef93ac1a94fb
2017-03-30 13:36:49 -07:00
Santiago Fernandez Madero 4f7e250ed1 Disable test (dotnet/corefx#17692)
Commit migrated from https://github.com/dotnet/corefx/commit/755f816d20536dbf87c80baa411a6da00bf94203
2017-03-30 10:44:00 -07:00
Stephen Toub 6445d60d14 Add test for HttpClient handling of trailer headers
Commit migrated from https://github.com/dotnet/corefx/commit/fede47996025201929aedd25b815a30b1a348a47
2017-03-27 14:03:49 -04:00
David Shulman cb3f31107b Fix Http test regarding uri fragments and redirection
No real test code change. But confirming that this test needs to be
skipped on Windows 7 due to a bug in WinHTTP with preserving fragments
in an uri during redirection. The WinHTTP bug was fixed in Windows 8.

Fixes dotnet/corefx#16133.


Commit migrated from https://github.com/dotnet/corefx/commit/7e1e66eb04075cbd69469c7498c4b04bd5db396b
2017-03-21 08:05:02 -07:00
Lakshmi Priya Sekar 6d612b34a7 Disable networking test on Windows7 pending investigation. (dotnet/corefx#16171)
Commit migrated from https://github.com/dotnet/corefx/commit/ee4ef6966d1e38726702923b19515b324b06530c
2017-02-14 21:14:54 -08:00
sepidehMS 016f9b537d Remove unnecessary PlatformSpecific labels from tests
Commit migrated from https://github.com/dotnet/corefx/commit/3294b7172c51869892debba78d774a4e1f382cd5
2017-02-07 15:46:35 -08:00
Lakshmi Priya Sekar 6bff1b3000 Fix networking test activeissues in System.Net.Http
Commit migrated from https://github.com/dotnet/corefx/commit/dd65f89ef9806067779eb63b884d9317dad68202
2017-02-03 12:31:59 -08:00
Stephen Toub 27e985cfa3 Replace "readonly static" with "static readonly"
There are ~4000 occurrences in corefx of "static readonly".  There are ~200 occurrences of corefx of "readonly static".  Replacing all of the straggler "readonly static" cases with "static readonly" to make things consistent.


Commit migrated from https://github.com/dotnet/corefx/commit/d9d1e815ad6c642cf5d61afa4a16726548598bb2
2016-12-09 10:27:00 -05:00
Stephen Toub 5c80441a2c More aggressively clean up disposable resource in Http tests
Most of these likely don't matter, but some of these can be keeping alive the underlying connections associated with the HttpClient instance, and it's possible that can lead to more resource contention / exhaustion.


Commit migrated from https://github.com/dotnet/corefx/commit/ec47d4e19f3215f75e652e8e5ff61cc4c253c056
2016-11-03 11:18:27 -04:00
David Shulman 637fa2d8b0 Disable another test
Ref dotnet/corefx#13188


Commit migrated from https://github.com/dotnet/corefx/commit/804d3aea2539aa1be5b49b94204f070cb134444b
2016-10-31 14:07:51 -07:00
Stephen Toub 45df74c422 Re-disable re-enabled HTTP tests that are still failing
Commit migrated from https://github.com/dotnet/corefx/commit/ccbc93652ad7570e3b7262ede4ae4cbb17bbc592
2016-10-28 09:01:13 -04:00
Alex Ghiondea 81e93c452c Re-enable tests for issues that have already been resolved.
Commit migrated from https://github.com/dotnet/corefx/commit/51394d7ca62027468d488b25a4ab87f4a12dc5ba
2016-10-26 15:00:58 -07:00
sxmichael 07d55fcb2a Mandatory http response status should be 100..1000 (dotnet/corefx#12938)
* Mandatory http response status should be 100..1000
* Added test for expected status codes
* Added OuterLoop attribute for 2 tests


Commit migrated from https://github.com/dotnet/corefx/commit/bd929648f648ee1e139b648266e9863e352baab5
2016-10-24 16:00:22 -04:00
Eric St. John f6f23740a5 Update Http tests to target ns1.7 + ns1.3
I had to add a namespace alias due to System.Configuration now being
defined by System.Runtime.


Commit migrated from https://github.com/dotnet/corefx/commit/6e86da5cc3efb88db6b932f01c9a4f9e66e84f8c
2016-10-20 14:31:18 -07:00
Justin Van Patten aa68f5ce2f Replace uses of Xunit.PlatformID with renamed TestPlatforms
Replace uses of `Xunit.PlatformID` with renamed `TestPlatforms` because
the old name conflicts with `System.PlatformID` and should be plural
according to the design guidelines for flags enums.


Commit migrated from https://github.com/dotnet/corefx/commit/5179dda7331b1e201519adf76ce9ae69ffe2a0f6
2016-10-01 17:18:41 -07:00
Jose Perez Rodriguez 1105adec7a Merge remote-tracking branch 'mainrepo/dev/api' into MergeDevApi
Commit migrated from https://github.com/dotnet/corefx/commit/a1989d82cff273db667638e4836ea7836f5c6eb9
2016-09-12 15:20:12 -07:00
Eric Eilebrecht be96f805d0 Work around known issues in "Ubuntu on Windows" (dotnet/corefx#11574)
The latest Windows 10 preview builds contain enough functionality in Ubuntu/Bash on Windows (a.k.a. Windows Subsystem for Linux, or WSL) that .NET Core mostly works now. With the fix for dotnet/corefx#11058, we can even build/test the CoreFx tree in this environment. Currently there are a few test failures; I've been working on identifying the causes of these, and filing bugs in the appropriate repos. 
This change implements workarounds for all of the current known issues in the "inner loop" tests. Mostly, I've just conditionally disabled tests when running in the WSL environment. 
There is still an issue, under investigation, causing non-deterministic failures in the System.Net.Http tests (Microsoft/BashOnWindowsdotnet/corefx#1068). And I haven't tried OuterLoop runs of anything but the networking tests. 

Commit migrated from https://github.com/dotnet/corefx/commit/d9aa92f6616d851256339318aadb89a6737e6d13
2016-09-09 20:10:01 -07:00
David Shulman 1b7fd15780 Fix WinHttpHandler to deal with nonstandard HTTP auth responses
WinHTTP returns an error from WinHttpQueryAuthSchemes if a server sends back a response with a scheme that isn't handled by WinHTTP. Many servers use custom auth schemes. A few don't even send a `WWW-Authenticate` header in the response at all (technically against RFC7235). To handle these cases and to match Desktop behavior, we ignore the error from WinHttpQueryAuthSchemes.

Fixes dotnet/corefx#11452 and dotnet/corefx#11456.


Commit migrated from https://github.com/dotnet/corefx/commit/ff50e500356f94c566baef786cc23e78cee870fd
2016-09-06 13:55:19 -07:00
David Shulman 9e67874b28 Fix WinHttpHandler for Basic auth with default credentials
We were getting an error "The parameter is incorrect" from WinHTTP when we tried to invoke default credential handling even for cases where the server doesn't use Negotiate or NTLM. Negotiate and NTLM are the only schemes that can use default credentials since they need to be transmitted via a challenge-response mechanism.

The fix here is to only set WinHTTP default credentials handling for Negotiate or NTLM schemes. Otherwise, it should behave as-if there were no credentials set.

Fixes dotnet/corefx#11266


Commit migrated from https://github.com/dotnet/corefx/commit/f48eb3480c51dd5b08fe6089c8d7a5041019d1e8
2016-09-02 12:40:33 -07:00
Jose Perez Rodriguez 6328e7431b Merge remote-tracking branch 'upstream/master' into dev/api
Commit migrated from https://github.com/dotnet/corefx/commit/ea0cc674b8116a10c18c2879390c39ec08df8020
2016-09-01 11:30:16 -07:00
David Shulman 935520c1dc Disable most networking tests for default CI runs
Lately, the CI system and test server infrastructure has been overloaded with many PRs. This is causing many networking tests to randomly fail due to resource exhaustion caused by so many simultaneous PR runs on the same CI machines. This occurrs not only when using an external test server endpoint (corefx-net.cloudapp.net) but also loopback servers.

To improve engineering efficiency for the team, we are moving most of the tests in the networking libraries from the default CI runs (innerloop). For developers working on networking libraries, the networking tests can be run by invoking the "outerloop" tests.

We will not be allowing any merges of PRs in the networking libraries unless the outerloop tests are also run by the developer.

This affects tests in the following libraries right now:

* System.Net.Http
* System.Net.Http.WinHttpHandler
* System.Net.Sockets
* System.Net.Security
* System.Net.WebSockets.Client

I will be working on fine tuning these exclusions (issue dotnet/corefx#11345) to try to bring back tests into the innerloop runs when we have begun to address the infrastructure issues.


Commit migrated from https://github.com/dotnet/corefx/commit/defbb8afd11b317f6b5cc2f4422a03d701b6dba3
2016-09-01 11:23:40 -07:00
David Shulman 9449dda9a7 Enhance LoopbackServer to return received data
Modified the test LoopbackServer so that it can return the received data in the helper methods. This allows more use of the
simple ReadRequestAndSendResponseAsync() method instead of having to use the more complex methods.

Modified a few HttpClient tests to take advantage of this. More tests will be simplified in future PRs.


Commit migrated from https://github.com/dotnet/corefx/commit/14c8ddd89be1fac31a472efdcaee184ba9d62e58
2016-08-26 12:11:43 -07:00
David Shulman 46241bfd10 Fix WinHttpHandler uri escaping for HTTP requests
There is a behavior difference between .NET Framework (Desktop) and
CoreFx. Desktop will send some reserved characters (such as square
brackets) on the wire as-is without any percent-encoding. CoreFx using
WinHttpHandler is doing additional percent-encoding on those characters.

This fix changes WinHttpHandler behavior so that it won't do any additional
percent-encoding. Whatever encoding System.Uri has done will be
transmitted as-is.

There is a separate problem where System.Uri itself doesn't
percent-encode these characters during normalization. That is due to
changes in the .NET Framework 4.5 timeframe (2012) where System.Uri was changed to
follow more IRI (RFC 3987) rules. One could argue that was the real
problem. But since this behavior is already baked into .NET Framework,
the right fix for the below issue is to match Desktop behavior.

We will be having a separate discussion/issue to analyze/debate whether System.Uri
needs to be changed (or not) in the future. The various URI and HTTP RFCs have
ambiguous language in these areas.

Fixes dotnet/corefx#11156


Commit migrated from https://github.com/dotnet/corefx/commit/429dfa4c320830ef3dc2d84f065064cc33239f1d
2016-08-25 14:14:57 -07:00
David Shulman 59efacec45 Add HTTP/2 support to WinHttpHandler
Windows 10 Anniversary release a.k.a Windows 10 Version 1607 added support to native WinHTTP for HTTP/2 protocol support. Added code to use this when sending request messages  with HTTP/2. This change affects both the System.Net.Http and System.Net.Http.WinHttpHandler library packages.

Added new tests that validate the functionality and verify the test client is running on the proper version of Windows 10.

Switched the HTTP/2 test server endpoint to www.microsoft.com since it supports HTTP/2.

Fixes dotnet/corefx#4870


Commit migrated from https://github.com/dotnet/corefx/commit/16246fde864d7f88f56ed0ac76055711116192e9
2016-08-18 13:58:54 -07:00
Krzysztof Wicher a59375763d Disable failing System.Net tests
Commit migrated from https://github.com/dotnet/corefx/commit/6460505710b213d0e3f9fc927c07318e58fdbd90
2016-08-10 16:26:10 -07:00
Eric Eilebrecht b42148aeae Avoid wrapping async I/O in synchronous methods in the HTTP tests, as this can lead to ThreadPool starvation, causing tests to run longer (waiting for the ThreadPool to inject enough threads) and possibly to time out.
Commit migrated from https://github.com/dotnet/corefx/commit/af17a7ab4bd0630f71e44bbe566bb712aeb86b5c
2016-07-13 15:19:30 -07:00
Cristian Pop 7a3d76b180 Adding multi-machine scripts and unifying configuration.
Commit migrated from https://github.com/dotnet/corefx/commit/c354b2d44f6988a20a9f7be4a1b996ef7fbc873a
2016-06-28 12:38:07 -07:00
Stephen Toub 50a73e1779 Fix HttpRequestMessage reuse handling in HttpClientHandler on Unix
HttpRequestMessages are meant to be used for a single request.  However, that checking is done by HttpClient rather than by HttpClientHandler.  As a result, if code bypasses HttpClient, e.g. by using HttpMessageInvoker or by using a custom HttpMessageHandler sitting between the HttpClient and the HttpClientHandler, the same HttpRequestMessage can be used multiple times without an exception being thrown warning of the invalid usage.  And on Windows, things happen to work, but with our Unix implementation was never expecting this scenario and doesn't work well with it:
- The handler is explicitly disposing of the request content stream rather than leaving that up to the request content's disposal to handle.
- The handler is removing the Content-Length header from the request message content, as a simple way to avoid overriding the Content-Length header that libcurl itself may send based on previous configuration.
- The handler is using ReadAsStreamAsync to get the request stream to send, but ReadAsStreamAsync caches the returned stream, so if the same request message is reused with the same Content, the stream will have already advanced to the end of the stream, and when the message gets reused, we won't have content to send.

This commit fixes that:
- We now don't dispose the request content stream.  That'll be left up to the request content's disposal.
- We now don't remove the ContentLength header from the request message.  We instead just check as we're writing out the headers whether the header is Content-Length, skipping it if it is.
- We now store the original position of a seekable stream that's provided to us, and at the end of the request, rather than disposing of the stream, we rewind to the original position if it exists.  (If the stream isn't seekable, reusing the request message wouldn't be possible anyway.)

This last point also fixes another theoretical issue.  When libcurl wants to go back to the beginning of the stream (e.g. in a redirect scenario where it needs to rewind), it asks us to seek back to the beginning.  We're currently seeking back to the exact position asked for.  But the stream may have come in to us already advanced beyond 0, in which case we need to seek back to the requested offset plus that original position rather than just the requested offset.

And in doing this, I noticed that we were inadvertently allowing a set of closure/delegate allocations due to inadvertently using some captured state in a place where we were trying to avoid that.  I fixed that as well.

We were also marking everything complete before we'd cleaned up all resources, which meant that any failures from such cleanup would go unnoticed.  I've fixed that to ensure we clean up all state before we officially declare the async operation done.


Commit migrated from https://github.com/dotnet/corefx/commit/650cb2698f02635ea69da3ec9637f6ad9e7229c5
2016-06-24 09:23:57 -04:00
Jeremy Barton 18178d80e2 Allow the HTTP2 protocol test to pass with untrusted chains on Debian.
The TLS context is set up to make this chain:
  CN=http2.akamai.com, O=Akamai Technologies Inc., L=Santa Clara, S=CA, C=US
  CN=Verizon Akamai SureServer CA G14-SHA2, OU=Cybertrust, O=Verizon Enterprise Solutions, L=Amsterdam, C=NL
  CN=Baltimore CyberTrust Root, OU=CyberTrust, O=Baltimore, C=IE
  CN=GTE CyberTrust Global Root, OU="GTE CyberTrust Solutions, Inc.", O=GTE Corporation, C=US

making use of the cross-signed Baltimore CyberTrust Root certificate.
Unfortunately, that chain is not trusted on Debian 8.4 (GTE CyberTrust Global Root was removed), and a combination of data and installed software results in the valid chain using the self-signed Baltimore root is never built.

To prevent this situation from making the tests show as a failure, selectively allow Debian 8 to succeed on an incomplete chain.


Commit migrated from https://github.com/dotnet/corefx/commit/316370ac1d58a90f6788ecb924b41cc93aec043e
2016-06-20 10:55:52 -07:00
Stephen Toub 8f623a92be Override HttpContent.CreateContentReadStreamAsync in MultipartContent
MultipartContent doesn't override CreateContentReadStreamAsync.  This means that a ReadAsStreamAsync operation will end up serializing all of the content to a MemoryStream, which can be problematic for very large content, preventing such content from being uploaded with some HttpClientHandlers.  This change overrides CreateContentReadStreamAsync to use a custom stream that delegates to all of the inner streams from each content.


Commit migrated from https://github.com/dotnet/corefx/commit/b1d20b427fb68f468740b5ad55c04d41064e1396
2016-06-14 23:23:47 -04:00
Stephen Toub eb6984022d Add test for dotnet/corefx#9357
Commit migrated from https://github.com/dotnet/corefx/commit/ab02479780441c1ab1b995e50492c592fbc9f7a9
2016-06-14 11:06:36 -04:00
Stephen Toub e7fad1b9dc Fix hanging System.Net.Http test
We've been plagued for the last few weeks by CI jobs on Windows that hang in System.Net.Http.Functional.Tests, causing the whole job to fail after it eventually times out after two hours. I managed to find a CI server that had a process still alive after having experienced the hang and was able to debug it.  The Dispose_DisposingHandlerCancelsActiveOperationsWithoutResponses test is creating three loopback servers and using HttpClient.GetAsync to access each of them.  It's then Disposing of the HttpClient to verify that requests which should have been canceled are canceled.  The problem is that there's a race condition.  We may end up canceling one of the requests before it even gets a chance to connect to the server.  As a result, the server remains stuck in an asynchronous accept on it socket, and at the end of the test, we're waiting for all of the servers to shutdown... deadlock.  The fix is simple: don't wait for the servers... we don't care about their results, and they'll all be torn down when we exit the inner delegate.


Commit migrated from https://github.com/dotnet/corefx/commit/99b7b5a9b9f23e8b94bd8c75ecf86bb71d24b6c4
2016-06-10 11:29:49 -04:00
Stephen Toub eb1d4e0d0a Add another test
This simply posts to a location that will redirect, with several hundred K of data in the request body. It reliably fails for me before the change and reliably succeeds after.


Commit migrated from https://github.com/dotnet/corefx/commit/a97d15faa7d90bae430ae920a251c23010869a22
2016-06-09 13:39:31 -04:00
Stephen Toub 3d6037f313 Change how request content is read in libcurl
libcurl wants to be able to call back to CurlHandler at arbitrary times to ask it to seek in the request content stream.  This can happen for redirects, for auth challenges, etc.  Handling this has been a challenge due to the way HttpContent is designed.

HttpContent provides two modes for accessing the data via Streams:
- Push: You call CopyToAsync(Stream, TransportContext) to have the data from the HttpContent copied into the target stream.
- Pull: You call ReadAsStreamAsync to get a stream that represents the data in the HttpContent, and you can read from that.

The pull model is ideal for libcurl.  It allows us to get a stream which we can jump around in if it's seekable, and we can request a new stream if it's not seekable. The push model is challenging, as we're forced to put in plcae an intermediary, a push-pull adapter that let's us effectively read from a type that's trying to write to us.

There is however an issue with the pull model.  With the push model, StreamContent's CopyToAsync tracks whether the stream has already been accessed, and if it has and if it's non-seekable, trying to call CopyToAsync again throws to alert you that rewinding simply isn't possible.  The pull StreamContent's ReadAsStreamAsync, however, does not.  This means that if you get a non-seekable stream and you call ReadAsStreamAsync again, you get back the same stream (or, rather, a read-only wrapper around the same stream) that is at the existing position rather than the original position.  Then resending that content will end up sending less data than it should have, resulting in failure, just not abruptly.

That issue caused us to go down the path of the more challenging push model and trying to use CopyToAsync.  However, recently that's been shown to have even worse effects.  We don't have the ability to cancel CopyToAsync, which means that if the first copy is still in-flight when we try to seek, we have no choice but to fail, even if the stream is actually seekable, as most are (e.g. memory streams, file streams, etc.)  This can happen deterministically in cases where libcurl decides to redirect before it's fully sent the request content, but it's also prone to race conditions even for cases where the request content is fully sent but the copy hasn't been officially marked as complete by the time libcurl tries to redirect.   ASP.NET recently began hitting this frequently on some machines in their lab runs.

While there's no perfect solution, the best solution is to go with the one that's the simplest code, the fastest code, and the deterministic outcome: the pull model.  This commit deletes a whole bunch of code that was there in support of the push model, adds just a bit of code to enable the pull model, and fixes up a couple of tests that were written to expect the push model.


Commit migrated from https://github.com/dotnet/corefx/commit/74cd3d619b3d3b1e963ca8bd33749af3aec99c05
2016-06-09 10:18:19 -04:00
Stephen Toub 2f0636a244 Allow whitespace after HTTP response header name
Be a bit more lenient in what we allow in the formatting of response headers on Unix. The RFC states that "Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace." However, whitespace between the header name and the colon is accepted by WinHttpHandler, by the .NET Framework, and by all browsers on which I tried it, and servers can easily include such whitespace; if they do and we're not tolerant of it, requests to such servers will fail.


Commit migrated from https://github.com/dotnet/corefx/commit/888a01cbcb1a98377ebf6e87e89a2551aac1654d
2016-06-07 09:38:20 -04:00
Stephen Toub 4077430754 Merge pull request dotnet/corefx#9024 from stephentoub/http_sendasync_tests
Add several HttpClientHandler tests related to content

Commit migrated from https://github.com/dotnet/corefx/commit/cdba60ecba957272a77ccc8245ab6ba29535380b
2016-06-01 14:19:34 -04:00
Stephen Toub ad4e7cb1ab Fix CurlHandler handling of redirects (dotnet/corefx#8946)
* Fix CurlHandler handling of redirects

- Relative urls in Location headers were not being handled correctly.  We now allow any url that TryCreate will parse using the current url as a base.
- We were only handling a subset of redirect status codes as redirects, trying to second-guess which status codes libcurl would redirect for, e.g. 300 wasn't being treated as a redirect. We now let libcurl do all the work.
- We should have been playing it safer with regards to clearing out credentials if we weren't sure a Uri redirect location was valid. Now we do.
- We were tracking state unnecessarily that we should have instead been
  asking libcurl for, e.g. the last url used in a redirect.  This also caused us to store the wrong RequestMessage.Uri in some cases where a location header came in but we didn't actually follow it.

Commit migrated from https://github.com/dotnet/corefx/commit/7bd18d682f0e201275c988e6263239ab84f6389b
2016-06-01 08:41:23 -04:00
Stephen Toub 3f7c097a58 Add several HttpClientHandler tests related to content
- Verify that request content isn't disposed until after response content is buffered
- Verify that request content isn't disposed until after request content is sent and response headers are received
- Verify that verbs which shouldn't send request content don't


Commit migrated from https://github.com/dotnet/corefx/commit/9c0eaa1b7a4812f50ac37f4adde516971d9b333a
2016-06-01 08:38:58 -04:00
Stephen Toub f9fc17df13 Remove innerloop dependencies on www.ssllabs.com
We have several innerloop tests that make HTTP calls during System.Net.Http.Functional.Tests out to www.ssllabs.com, which has SSL endpoints for different SSL protocols.  This commit avoids using that server during innerloop tests.  The tests are moved to outerloop, and some replacements using a localhost are added to innerloop.


Commit migrated from https://github.com/dotnet/corefx/commit/8a9402b33d46166d1a3129a7c2cae0334b00c4b6
2016-05-31 17:05:10 -04:00
David Shulman aed74e56f1 Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/53c50e84f6be882f896d01b5ec99d2183cb44c48
2016-05-14 19:46:36 -07:00
David Shulman 354c2e5b9c System.Net.Http 4.1 contract implementation
As per approved dotnet/corefx#7623, add remaining properties to HttpClientHandler for
all platforms.

Move pre-existing Unix-only Http tests to run for all platforms.

Ensure that "credentials" related properties are secure by default and have
an initial (default) value of null.


Commit migrated from https://github.com/dotnet/corefx/commit/361b66146506a58f7d2c27224cc02f9583cd0639
2016-05-14 17:07:27 -07:00
stephentoub 514492a454 Don't cancel all requests when HttpClient disposed on Unix
On Unix when an HttpClientHandler is disposed, we cancel all outstanding operations associated with that handler.  It turns out this isn't the desired behavior (aka the behavior of WinHttpHandler), which is that we should cancel all outstanding operations that haven't yet published its HttpResponseMessage, but for requests where the HttpResponseMessage has been published, it should remain valid.

This commit tweaks the behavior accordingly and adds a test for it.


Commit migrated from https://github.com/dotnet/corefx/commit/f949d92b3ee26168277f56fbd2c6686505ea0b4a
2016-05-12 14:27:51 -04:00