Commit Graph
1535 Commits
Author SHA1 Message Date
Geoff Kizer d803a21ca8 add logging for drain, and update tests to reflect higher limit for managed handler
Commit migrated from https://github.com/dotnet/corefx/commit/0070410383dfc528f394f3b73787aa9e575afc62
2018-02-21 15:47:40 -08:00
Geoff Kizer 00c926a26f rework content length logic to drain buffer before doing length check
Commit migrated from https://github.com/dotnet/corefx/commit/3584bdbfd21c0f4b02bffe1170febb2e6fa9c0ad
2018-02-21 14:38:05 -08:00
Geoff Kizer f8d6e9d663 address review feedback
Commit migrated from https://github.com/dotnet/corefx/commit/5c622083a4a2228b2b490929da6d94b97c6f6e33
2018-02-21 10:51:28 -08:00
Geoff Kizer 6bdeebdc0c add response stream drain
Commit migrated from https://github.com/dotnet/corefx/commit/3abd27db07e592629b53bbaca26dd9c8c4411ff1
2018-02-20 21:25:11 -08:00
Stephen Toub e030befe43 Several perf improvements/tweaks for SocketsHttpHandler (dotnet/corefx#27231)
* Several perf improvements/tweaks for SocketsHttpHandler

- Chunked reads from buffer.  We now process as much of the buffer as we can synchronously during ReadAsync, rather than returning once we hit the end of a chunk.  For very small chunks that arrive quickly, this results in a huge perf increase, e.g. best case for the optimization, with lots of 1-byte chunks getting buffered together, it's now 10x faster.  With 100-byte chunks buffered together, it's 2x faster.

- Blitting byte[] to output for known headers.  Rather than using WriteStringAsync to output all header names, we now use WriteBytesAsync for known headers, with the headers precomputed into byte[]s and cached.

- Removed delegate/closure allocation from connection.  We were accidentally closing over a cancellation token, resulting in an extra delegate and closure allocation in ConnectHelper.  Also reduced the size of the EstablishSslConnectionAsync state machine by splitting the method in order to remove several arguments from being included.

- Use Utf8Formatter for hex values.  Switched from custom formatting of hex values to just use Utf8Formatter.TryFormat.

- Avoid buffering in HttpConnection.CopyToAsync(Stream).  This is used when we want to copy the whole source stream until EOF (e.g. for a Connection: close response), and thus we can skip the buffer and use the source stream's CopyToAsync directly.

- Added a test to exercise various size chunks, line endings, ReadAsync vs CopyToAsync, etc.

- Fix CopyToAsync cancellation handling.  Even though we'll abort the connection when cancellation is requested, we still need to pass the token to the destination stream's WriteAsync to give it the opportunity to cancel.  Also properly pass the buffer size through to the underlying stream's CopyToAsync where appropriate.

- Small miscellaneous cleanup, like removing a few unused arguments from methods, fixing an assert to validate the right thing, etc.

* Address PR feedback

* Fix test on netfx


Commit migrated from https://github.com/dotnet/corefx/commit/d5351fe933f0f4682ac465b656b2a438b076c24e
2018-02-20 20:54:16 -05:00
Stephen Toub eac46c0cce Expose SocketsHttpHandler.ConnectTimeout/Expect100ContinueTimeout (dotnet/corefx#27292)
Commit migrated from https://github.com/dotnet/corefx/commit/3b2d39593672a7f49946e453a42cfae62f2ac88f
2018-02-20 18:30:34 -05:00
Max Kerr 5953018eb9 Log when an insecure Https -> Http redirect is blocked (dotnet/corefx#27077)
.NET Core does not allow insecure redirects from https to http, but .NET Framework does. Developers have had some trouble diagnosing the issue when they run into this difference. This change adds logging to help developers track down what is going on.

Commit migrated from https://github.com/dotnet/corefx/commit/1fd7d79fc36ca113bdabbee4204e15ae5bcde24a
2018-02-20 14:31:16 -08:00
Stephen Toub a471023af9 Increase timeout on ConnectTimeout_TimesOutSSLAuth_Throws test (dotnet/corefx#27294)
Hopefully fixes dotnet/corefx#27291.  If it fails again, we'll need to look for a deeper reason than just CI hammering the server and causing things to take longer.

Commit migrated from https://github.com/dotnet/corefx/commit/7c3caab0801dc1542ab21c79fab2194a525c952f
2018-02-20 16:05:47 -05:00
Lakshmi Priya Sekar 548687e68b Merge pull request dotnet/corefx#26979 from Priya91/newhttpauth
Add test infra for auth testing.

Commit migrated from https://github.com/dotnet/corefx/commit/ff123e89989b2b34e82c854ea597626d884d52ba
2018-02-20 11:06:08 -08:00
Geoff Kizer 1ff27f16dd SocketsHttpHandler: Don't reuse connection with extraneous received data (dotnet/corefx#27265)
* don't reuse connection with extraneous received data

* add tracking issue


Commit migrated from https://github.com/dotnet/corefx/commit/5a57de7524fa3c3a2ba2b4f643f30464f917e14f
2018-02-20 08:20:20 -05:00
Geoff Kizer b17b24ae2d Merge pull request dotnet/corefx#27255 from geoffkizer/fixcl
SocketsHttpHandler: remove Content-Length header if Transfer-Encoding: chunked is present

Commit migrated from https://github.com/dotnet/corefx/commit/f9853fafb6e49c1c6e94f8c3130af9da4a1574a2
2018-02-19 22:07:37 -08:00
Geoff Kizer f063879da7 remove CL if TE present
Commit migrated from https://github.com/dotnet/corefx/commit/f9c486d14ec01e98b9e73b4eb23f729783678e3c
2018-02-19 11:32:24 -08:00
Geoff Kizer 98ff22b12c modify test to work around CL population issue
Commit migrated from https://github.com/dotnet/corefx/commit/ff5318905c9134d5fbf87b6597f72d331bc9a029
2018-02-19 11:28:15 -08:00
Stephen Toub 51b78a974c Implement SocketsHttpHandler's Expect100ContinueTimeout and ConnectTimeout (dotnet/corefx#27242)
With the expectation that we'll want to expose this in 2.1, implement Expect100ContinueTimeout and ConnectTimeout.  The members are currently internal but can be flipped public easily once the APIs are approved.  This also fixes an issue with cancellation around the connect phase, where a cancellation request that came in during the SSL auth phase would not be respected.

Commit migrated from https://github.com/dotnet/corefx/commit/01fa16ffd618846a913cad719269c8bb441ceb28
2018-02-19 11:06:18 -05:00
Caesar Chen 987d73a579 Enable SendReceive_VaryingLengthBuffers_Success on Windows run (dotnet/corefx#27181)
* enable test on Windows run

* delete script

* disable test issue dotnet/corefx#27211

* disable test see dotnet/corefx#27217


Commit migrated from https://github.com/dotnet/corefx/commit/d3a69ff4448a0bd4df12e6af481898825c066c67
2018-02-16 16:03:46 -08:00
Lakshmi Priya Sekar 130436c7f3 More test fixes from CI.
Commit migrated from https://github.com/dotnet/corefx/commit/3fe39953a3213f60110e319cef869958a9638c49
2018-02-16 11:24:15 -08:00
Stephen Toub b6b2da9344 Improve test coverage of SocketsHttpHandler (dotnet/corefx#27135)
* Improve test coverage of SocketsHttpHandler

Used code coverage information to write targeted tests to cover various uncovered paths in SocketsHttpHandler.  Along the way fixed a variety of issues relating to throwing the wrong exception type, a stack overflow due to an unexpected recursive call, etc.

* Address PR feedback

* Re-disable a test


Commit migrated from https://github.com/dotnet/corefx/commit/39677219aaeab8c6591b625ab2874acb17eaf4ef
2018-02-16 12:02:45 -05:00
Max Kerr cd85b45b2d Modify StreamContent to use default CopyToAsync buffer size when no size is provided (dotnet/corefx#27176)
* Add a tentative fix

* Minor fixes.

* Remove unused default value.

* Re-order error checks for compatibility reasons.

* Add a test to pin exception behavior when both parameters are incorrect.


Commit migrated from https://github.com/dotnet/corefx/commit/c28fbce3ce31cc0274b14e6e4ae08a84ec04ed1b
2018-02-16 07:18:59 -05:00
Lakshmi Priya Sekar 086a261943 More test fixes from CI runs.
Commit migrated from https://github.com/dotnet/corefx/commit/29374f83897d19995b640c1d663e68dfb9fb1058
2018-02-15 16:59:26 -08:00
Lakshmi Priya Sekar 29936a5929 Response to PR feedback.
Commit migrated from https://github.com/dotnet/corefx/commit/9721f49e0838a3b3355437cb1f6882d9d62ab557
2018-02-15 14:24:44 -08:00
Geoff Kizer ea61dedad9 Merge pull request dotnet/corefx#27151 from geoffkizer/sslproxytunnel
SocketsHttpHandler: refactor pool manager logic to enable SSL proxy tunneling support

Commit migrated from https://github.com/dotnet/corefx/commit/6e3bcbec17273cd38db67e47e7a2975a25160ac2
2018-02-15 13:39:32 -08:00
Stephen Toub 96239ef682 Streamline SocketHttpHandler's ParseStatusLine validation (dotnet/corefx#27163)
* Streamline SocketHttpHandler's ParseStatusLine validation

For a typical status line like "HTTP/1.1 200 OK", cuts the time of ParseStatusLine almost in half.

* Address PR feedback


Commit migrated from https://github.com/dotnet/corefx/commit/c8d23b4941b3b620633db397a0094f55b01be22b
2018-02-15 16:04:40 -05:00
Stephen Toub b47f6bd40f Fix race condition in PostAsyncExpect100Continue_RetryOnConnectionClosed_Success test (dotnet/corefx#27148)
Commit migrated from https://github.com/dotnet/corefx/commit/28799e8af0556efe1b9e5e98b700460951ae9eb2
2018-02-15 14:59:30 -05:00
Geoff Kizer ab1edffdc0 address review feedback
Commit migrated from https://github.com/dotnet/corefx/commit/46785d3ae61987ae8ae389b2138645e82b54efb0
2018-02-15 10:55:32 -08:00
Tomas Weinfurt 5d8c6a618a disable two tests on ubuntu 18 while investigating root casue (dotnet/corefx#27144)
Commit migrated from https://github.com/dotnet/corefx/commit/d00eb7ec42434b0a7e2c3b4f6cd88c896ebaa30f
2018-02-15 05:47:50 -05:00
Geoff Kizer 76301c7104 add code to establish proxy tunnel for SSL
Commit migrated from https://github.com/dotnet/corefx/commit/d84a28844502bcf30538a18e30e33118ca879467
2018-02-14 18:43:15 -08:00
Geoff Kizer 6d6f3b6a0b reorganize pool manager logic and rework HttpConnectionKey to support ssl proxy tunneling
Commit migrated from https://github.com/dotnet/corefx/commit/39ed24e9f6f55d6077742776e154ead199e1b3a0
2018-02-14 18:25:38 -08:00
Lakshmi Priya Sekar 4fc5a16b79 Mark failing tests with issue.
Commit migrated from https://github.com/dotnet/corefx/commit/828468a258cfba872c84c3976835e9c664f68dee
2018-02-14 17:24:03 -08:00
Lakshmi Priya Sekar 705c8ae243 Add tests to all handlers.
Commit migrated from https://github.com/dotnet/corefx/commit/aa2482155262063229ea3f0e5d868890d8490415
2018-02-14 15:52:54 -08:00
Lakshmi Priya Sekar 5f4349f7f0 Fix test
Commit migrated from https://github.com/dotnet/corefx/commit/102e4d3c731e1765a21a3a5fd3e908c428ef4a88
2018-02-14 15:52:25 -08:00
Lakshmi Priya Sekar e9414ba693 Add test infra for auth testing.
Commit migrated from https://github.com/dotnet/corefx/commit/a7d6718d2919ef81a5cebb0ce92a53b4989234d4
2018-02-14 15:52:23 -08:00
Geoff Kizer cc2e02b853 Merge pull request dotnet/corefx#27088 from geoffkizer/refactorloopbackserver
reorganize and cleanup some LoopbackServer code

Commit migrated from https://github.com/dotnet/corefx/commit/46267c1dbe46f0127e670ce25933ff49a5ec9d6e
2018-02-14 11:13:34 -08:00
Jeremy Barton ffe1b07233 Add FixedTimeEquals and other crypto helper routines as public API
Commit migrated from https://github.com/dotnet/corefx/commit/3872bafe8186a3e74cb66efa4a2835d60ed67ba2
2018-02-14 07:33:30 -08:00
Geoff Kizer 29cb5540c4 fix tests from merge
Commit migrated from https://github.com/dotnet/corefx/commit/b028092ce1af45e109edb0609b7b8cef42ee8a99
2018-02-13 16:04:27 -08:00
Geoff Kizer bf6635fcfd add response generation overloads
Commit migrated from https://github.com/dotnet/corefx/commit/6943fc7c0e92359e6335a618f6ff5ee8402af4ac
2018-02-13 16:04:26 -08:00
Geoff Kizer c9a61b410b address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/6ab005635528a03daa52ca727a4a74dcc0316830
2018-02-13 15:44:00 -08:00
Geoff Kizer b94eefba0f reorganize and cleanup some LoopbackServer code
Commit migrated from https://github.com/dotnet/corefx/commit/ec6a7215bb28a061d2357d8c3874447bc575132d
2018-02-13 15:43:59 -08:00
Caesar Chen 8bdfd2f594 Change HTTP default request version to HTTP/2 (dotnet/corefx#27079)
* change http default request version

* fix innerloop test


Commit migrated from https://github.com/dotnet/corefx/commit/f7a852f64bf20889579be70710f386a8d4802a34
2018-02-13 15:24:22 -08:00
Stephen Toub 8f3ddb7597 Enable SocketsHttpHandler cancellation support (dotnet/corefx#27029)
* Enable SocketsHttpHandler cancellation support

This change significantly improves the cancellation support in SocketsHttpHandler.  Previously we were passing the CancellationToken around to every method, eventually bottoming out in calls to the underlying Stream which then ends up passing them down to the underlying Socket.  But today Socket's support for cancellation is minimal, only doing up-front checks; if cancellation is requested during the socket operation rather than before, the request will be ignored.  Since HttpClient implements features like timeouts on top of cancellation support, it's important to do better than this.

The change implements cancellation by registering with the CancellationToken to dispose of the connection.  This will cause any reads/writes to wake up.  We then translate resulting exceptions into cancellation exceptions.  When in the main SendAsync method, we register once for the whole body of the operation until the point that we're returning the response message.  For individual operations on the response content stream, we register per operation; however, when feasible we try to avoid the registration costs by only registering if operations don't complete synchronously.  We also account for the case that on Unix, closing the connection may result in read operations waking up not with an exception but rather with EOF, which we also need to translate into cancellation when appropriate.

Along the way I cleaned up a few minor issues as well.

I also added a bunch of cancellation-related tests:
- Test cancellation occurring while sending request content
- Test cancellation occurring while receiving response headers
- Test cancellation occurring while receiving response body and using a buffered operation
- Test that all of the above are triggerable with CancellationTokenSource.Cancel, HttpClient.CancelPendingRequests, and HttpClient.Dispose
- Test cancellation occurring while receiving response body and using an unbuffered operation, either a ReadAsync or CopyToAsync on the response stream
- Test that a CancelPendingRequests doesn't affect unbuffered operations on the response stream

There are deficiencies here in the existing handlers, and tests have been selectively disabled accordingly (I also fixed a couple cases that naturally fell out of the changes I was making for SocketsHttpHandler).  SocketsHttpHandler passes now for all of them.

* Add test that Dispose doesn't cancel response stream


Commit migrated from https://github.com/dotnet/corefx/commit/53be85c2fe473fdea8c001e3d9fd81dd478b858e
2018-02-13 16:30:34 -05:00
Stephen Toub 62912af578 Fix SocketsHttpHandler connection pool accounting for dropped connections (dotnet/corefx#27068)
When MaxConnectionsPerServer is set to anything other than int.MaxValue, the SocketsHttpHandler pool keeps track of the number of connections handed out, and this count is updated when a connection is disposed.  But if a response stream isn't disposed of, resulting in the connection never being disposed of, the count may never be updated.  This fix adds an HttpConnection derived type that simply adds a finalizer, making it pay-for-play when MaxConnectionsPerServer is set to something other than the default.

Commit migrated from https://github.com/dotnet/corefx/commit/ffa5db357252913c52e0cdad63c1573020185f6e
2018-02-13 08:38:32 -05:00
Stephen Toub f8e6f41b81 Clear initlocals in a bunch of assemblies (dotnet/corefx#26993)
* Clear initlocals in a bunch of assemblies

Sets
```XML
<ILLinkClearInitLocals>true</ILLinkClearInitLocals>
```
for the assemblies:
    - System.IO.FileSystem
    - System.IO.Pipes
    - System.Memory
    - System.Net.Http
    - System.Net.Http.WinHttpHandler
    - System.Net.NameResolution
    - System.Net.NetworkInformation
    - System.Net.Primitives
    - System.Net.Requests
    - System.Net.Security
    - System.Net.Sockets
    - System.Net.WebSockets
    - System.Net.WebSockets.Client
    - System.Net.WebSockets.WebSocketsProtocol
    - System.Private.Uri
    - System.Runtime
    - System.Runtime.Extensions

Eventually we'd ideally set the flag for the whole repo; these are just the ones I audited thus far.  In a few cases I had to make code changes to adapt, where the code was expecting stackallocs to be cleared.  I also looked at a few other projects (System.Collections, System.Runtime.Numerics) where there were more significant dependencies on clearing and I decided to leave those for later.

* Disable ILLinkClearInitLocals running on Unix until it works there


Commit migrated from https://github.com/dotnet/corefx/commit/f0a032e4a1c8a848574a5db3e69e8a6fa0aae91e
2018-02-13 06:30:25 -05:00
Geoff Kizer b250d954d3 Merge pull request dotnet/corefx#27069 from stephentoub/cachessl
Cache SslClientAuthenticationOptions on SocketsHttpHandler pool

Commit migrated from https://github.com/dotnet/corefx/commit/a438733f09a739bfbd4b9f945ba049386858019a
2018-02-12 23:11:11 -08:00
Max Kerr 717083f0d4 Clear Authorization Headers on Redirect (dotnet/corefx#26864)
When a user has added an Authorization header to a request via the HttpClient DefaultRequestHeaders Authorization field, ensure that header is stripped on redirect.

This change adds a method to strip Authorization headers that were set via the HttpClient DefaultRequestHeaders Authorization field, and calls that method on redirect. In addition, it adds a test to ensure that this behavior occurs as expected.

The new method ResetAuthRequestHeaders is based on the method ResetCookieRequestHeaders, which is used to reset cookie headers on redirect.

The issue also occurs in CurlHandler, but the fix is slightly different. Rather than remove the headers that have already been set, we can instead just skip them when copying over the new headers to the redirected request.

Fixes dotnet/corefx#26426

Commit migrated from https://github.com/dotnet/corefx/commit/7e6396b2bcb4d372b199cfb7b3b13e290c441124
2018-02-12 11:28:09 -08:00
Stephen Toub d1e0b0b1bd Fix HttpClientMiniStress.UnreadResponseMessage_Collectible test (dotnet/corefx#27061)
The async state machine was holding a reference to the response content object, which in turn prevented the response stream from being collected.

Commit migrated from https://github.com/dotnet/corefx/commit/6c9b62981190ae5886196f37d0f5dc614f4b0244
2018-02-12 13:39:02 -05:00
Stephen Toub 35aa72b9a7 Cache SslClientAuthenticationOptions on SocketsHttpHandler pool
For the common case, we can just use a singleton cached instance with settings computed when the pool is created.  Only if it's accessed via HttpClientHandler with a server certificate callback do we need to still create an instance per request, in order to wrap the delegate to provide the expected semantics.


Commit migrated from https://github.com/dotnet/corefx/commit/911d4aff095f1c8648334d4a221c217cd09e466b
2018-02-12 12:17:33 -05:00
Geoff Kizer a8ffcf7322 fix stress response generation, and disable failing test (dotnet/corefx#27059)
Commit migrated from https://github.com/dotnet/corefx/commit/472c3d95749910ba600df296bbf01d78d7c4f6d8
2018-02-12 07:25:24 -05:00
Stephen Toub ee5f5d76a1 Tweak CurlHandler SSL not supported messages to be more helpful (dotnet/corefx#27043)
* Tweak CurlHandler SSL not supported messages to be more helpful

* Address PR feedback


Commit migrated from https://github.com/dotnet/corefx/commit/9cde3e174b2495cbcdf95995aea0bea4030d4aa9
2018-02-12 05:27:57 -05:00
Geoff Kizer 2927c099bf Merge pull request dotnet/corefx#26989 from geoffkizer/fixcookiehandling
SocketsHttpHandler: Fix some issues with cookie handling, and add cookie tests

Commit migrated from https://github.com/dotnet/corefx/commit/8cee267154ef9dc6dde7a76a828844a200437872
2018-02-11 18:23:50 -08:00
Geoff Kizer e4d9a6c5c8 fix tests on netfx
Commit migrated from https://github.com/dotnet/corefx/commit/c7cc2a879d0a5b5f039caff36bef0c99f52604a2
2018-02-11 14:49:42 -08:00
Geoff Kizer ef25741e58 consolidate cookie tests
Commit migrated from https://github.com/dotnet/corefx/commit/c20262c69a93449498d511014e9e69bad18f987a
2018-02-11 12:38:20 -08:00