Commit Graph
1229 Commits
Author SHA1 Message Date
Stephen Toub 8909da570e Fix several PostScenarioTest tests
Tests expect that IOExceptions and InvalidOperationExceptions from SendAsync are wrapped in HttpRequestExceptions.


Commit migrated from https://github.com/dotnet/corefx/commit/4ed7139a9755db8a1a1c50a1365d8ab15c66fd9a
2017-06-30 17:11:44 -04:00
Stephen Toub ca58a45b18 Fix SafeFreeContextBufferChannelBinding.ToString()
One of the Windows-only tests is expecting SslStream's ChannelBinding's ToString() to output the data from the binding in a specific format, matching what WinHttp's outputs.  This makes that happen.  And enables more tests.


Commit migrated from https://github.com/dotnet/corefx/commit/0cd7eeabb6b91c44827592bd45f8312dcb961388
2017-06-30 17:11:44 -04:00
Stephen Toub 96d042f9ab Fix handling of 0-byte reads
And re-enable some tests that were tripping over them.


Commit migrated from https://github.com/dotnet/corefx/commit/32b5f3e3fb8ae4611ac1b2edce11d54849ba19f2
2017-06-30 17:11:44 -04:00
Stephen Toub 55108cffa3 Merge pull request dotnet/corefx#21750 from stephentoub/fix_linux_tests
Enable a bunch of ManagedHandler tests

Commit migrated from https://github.com/dotnet/corefx/commit/3435cab26d7362169e8e19c2ec711d8126dc42db
2017-06-30 17:09:26 -04:00
Stephen Toub 112aba715d Enable a bunch of tests for ManagedHandler
Commit migrated from https://github.com/dotnet/corefx/commit/eeb86610d8bcb9b38733d57279baf93e9ae68274
2017-06-29 22:01:11 -04:00
Stephen Toub 3b4a6c1854 Add DefaultProxyCredentials support
Commit migrated from https://github.com/dotnet/corefx/commit/c4cec4291648936e84fb8ed06c705df259514be9
2017-06-29 21:56:56 -04:00
Stephen Toub b6ae9abdf1 Add initial support for http_proxy
Commit migrated from https://github.com/dotnet/corefx/commit/06bb29fee02d969e4efef970663235e7fde797bc
2017-06-29 21:43:05 -04:00
Cristian Pop 23a2417388 Tracking ETW UAP test failures against a single issue. Global mutex is not supported in UAP. (dotnet/corefx#21732)
* Removing Global mutex bug ID. Tracking ETW UAP test failures against a single issue.
* Disabling EKU tests for UAP.

Commit migrated from https://github.com/dotnet/corefx/commit/12632fd50d02c1b1934cac13edc8225304ac91a5
2017-06-29 16:22:14 -07:00
David Shulman 7fa3bc181b Merge pull request dotnet/corefx#21691 from davidsh/nocache_uwp
Fix HttpClientHandler on UAP to use WinRT NoCache enum

Commit migrated from https://github.com/dotnet/corefx/commit/e40c2be03a5a4690f187b19bdd97e5b9924f5578
2017-06-29 15:26:03 -07:00
Stephen Toub 85048fcbed Merge pull request dotnet/corefx#21679 from stephentoub/httpperf
Several allocation improvements for HttpClient/ManagedHandler

Commit migrated from https://github.com/dotnet/corefx/commit/6bf1e7c3032d3c24d5a41bbd880549ef4a8de2da
2017-06-29 13:34:58 -04:00
Stephen Toub 3fbe23325e Address PR feedback
- Alphabetize consts
- Remove ValueTask dependency from HttpClient/Content, as it causes issues for the netfx/net46 builds


Commit migrated from https://github.com/dotnet/corefx/commit/d2af4889d35d63e287f6c16cffee5baf58dd4925
2017-06-29 08:09:06 -04:00
David Shulman 9de4463148 Fix HttpClientHandler on UAP to use WinRT NoCache enum
Since System.Net.Http APIs default to not using any cache, we need to
turn off caching at the WinRT layer. If supported, we set the
CacheControl.ReadBehavior to use the NoCache enum value. Otherwise,
we use the next best enum option.

Removed some unneeded try/catch handling when we previously
needed to handle compiling with older SDKs and trap JIT error.
This is no longer needed for NETStandard20.

Fixed some typos from a previous PR.

Fixes dotnet/corefx#7877


Commit migrated from https://github.com/dotnet/corefx/commit/1cf87a19d450040a0ad53c5f9580c5f5ddadd4e1
2017-06-28 20:57:36 -07:00
Stephen Toub ef2716206b Avoid allocating request headers for simple POST
Commit migrated from https://github.com/dotnet/corefx/commit/84956f407c925eb2b8c52bb335caa88efef9b28a
2017-06-28 21:41:58 -04:00
Stephen Toub 7273e9def8 Make fields on HttpRequest/ResponseHeaders pay-for-play
There are currently 9 reference fields on HttpResponseHeaders and 5 reference fields on HttpRequestHeaders that are used to cache lazily-instantiated collections when accessing strongly-typed properties on the headers objets.  That's 14*8==112 bytes of fields allocated per request, even if not used.  This commit lifts those fields into a lazily-allocated array; this makes them a bit more expensive when they're used, but reduces allocation when they're not.


Commit migrated from https://github.com/dotnet/corefx/commit/7baf36daceb4cced1a8165cd5c81a28b8807c02c
2017-06-28 21:41:57 -04:00
Stephen Toub 39a163c5cb Avoid enumerator allocation for each written header
Commit migrated from https://github.com/dotnet/corefx/commit/fe15cecd7f32e584c72b21a529cd34f371e28283
2017-06-28 21:41:57 -04:00
Stephen Toub 4013121804 Avoid Task allocation for CreateContentReadStreamAsync
Most HttpContents produce the Stream from CreateContentReadStreamAsync synchronously, which means CreateContentReadStreamAsync is allocating a Task to wrap that stream unnecessarily.  While we can't change the existing protected API to return ValueTask instead of Task, we can add an internal API that we use instead.  The new base virtual just delegates to the existing Task-based overload.  Then derived implementations can override this; such derived implementations can just do the more efficient thing if they're sealed, or if they're not sealed, do so when they're sure a derived type isn't overriding the delegated implementation, e.g. by checking the concrete type of the instance.


Commit migrated from https://github.com/dotnet/corefx/commit/01abf38cac641981db1cbbf74012ddbbf0d768df
2017-06-28 21:41:57 -04:00
Stephen Toub 62951423f9 Replace ConcurrentDictionary in pool with simpler striped locked hash sets
ConcurrentDictionary is optimized for few writes / lots of reads, but this usage is basically only writing.  At that point we might as well use a simpler data structure that doesn't allocate on every write. (This is likely all going to be replaced or revised in the future, anyway.)


Commit migrated from https://github.com/dotnet/corefx/commit/155f50fc8862b34304963a8813e48d15a4b80698
2017-06-28 21:41:57 -04:00
Stephen Toub 87e60e0729 Combine ParseResponseAsync into SendAsync
A bit less manageable, but we're otherwise unnecessarily incurring several more allocations.


Commit migrated from https://github.com/dotnet/corefx/commit/0475aaa4f334ea8e5302d5e4ff2f18df97d7a569
2017-06-28 21:41:57 -04:00
Stephen Toub 1df2ff2b70 Avoid ManagedHandler allocating request headers for simple case
Commit migrated from https://github.com/dotnet/corefx/commit/7aea2372d41a21155b93ae685481abd19092fa56
2017-06-28 21:41:57 -04:00
Stephen Toub 3dc8b9ee99 Lazily-initialize general headers in HttpResponseHeaders
Commit migrated from https://github.com/dotnet/corefx/commit/79ae7ebf5f7e792e35c9b68af6d148b5ef24c818
2017-06-28 21:41:57 -04:00
Stephen Toub a3c49ab69d Lazily-initialize HttpRequestHeader's general headers
Commit migrated from https://github.com/dotnet/corefx/commit/5481b8f00f22a8504dcf33900605702ed42c8e39
2017-06-28 21:41:57 -04:00
Stephen Toub 53f0947a46 Format Uri port value without allocating
Commit migrated from https://github.com/dotnet/corefx/commit/9b87e49b5ce2b6e36ad299c0eeca67e6ce7f7ce7
2017-06-28 21:41:57 -04:00
David Shulman 7e59e3b2a7 Clarify default credentials usage for HttpClientHandler on UAP
This PR clarifies how credential handling and specifically default
logged-on credentials actually works on the UAP platform.

First, "default credentials" are the current credentials of the
logged-on user, typically on an enterprise network joined to an
Active Directory domain. When these credentials are sent to a
proxy or server, only Negotiate, Kerberos, or NTLM schemes are
used. Those credentials can never be sent via other schemes
like basic or digest.

.NET Framework traditionally has two ways for developers to specify
using default logged-on credentials to send to the server. Either
set the .UseDefaultCredentials property to true or specify
CredentialCache.DefaultCredentials to the .Credentials property.

For proxy credentials, the developer could pass DefaultCredentials
via the custom IProxy object or via the .DefaultProxyCredentials
property.

.NET Framework would send default credentials anywhere (intranet
or internet) if specified by the developer.

The UAP platform implementation of System.Net.Http uses a different
set of rules for sending default credentials. It is based on whether
the app has Enterprise Authentication capability as well as if the
endpoint is specified in an intranet zone. This design is part of
the base native WinInet and WinHTTP stacks. It was a design choice
to provide optimum security as well as convenience for developers
writing apps for enterprise scenarios.

This PR does a few things. First, it keeps the .NET ICredentials
properties stored separately so that they correctly round-trip
on get and set. .NET NetworkCredential has 3 parameters (domain,
user, password). But WinRT PasswordCredential only has 2 parameters
(user, password). We now convert to the WinRT objects only when
we need to use them.

Second, this PR clarifies that the .UseDefaultCredentials property
is basically a no-op because the API models of default credentials
handling is different on the UAP platform as described above.

These platform differences will be documented here:
https://github.com/dotnet/corefx/wiki/ApiCompat

Fixes dotnet/corefx#19642
Fixes dotnet/corefx#21510


Commit migrated from https://github.com/dotnet/corefx/commit/2c33453f3e4064c75d404c6f3590ddf00a377d10
2017-06-28 11:50:27 -07:00
David Shulman 65782675d6 Fix some TLS related HttpClientHandler properties for UAP (dotnet/corefx#21630)
Due to platform differences on UAP and the current use of WinRT APIs to
implement that HTTP stack, a few properties won't have the same defaults
or behavior.

CheckCertificateRevocationList default value is true for UAP and can't
be changed. However, on UAP, revocation checking that results in an
indeterminate status (i.e. revocation server offline) is treated the
same as a valid result. This is the behavior of the underlying WinRT
APIs.

SslProtocols default value is SslProtocols.None which is the same as the
rest of .NET Core. 'None' means to use the system default. However, changes
to this property value will be ignored.

Similar to the decision made in PR dotnet/corefx#21403, we don't throw PNSE for these
differences. Instead we just no-op on the property setter.

The behavior differences will be documented in:
https://github.com/dotnet/corefx/wiki/ApiCompat

Contributes to dotnet/corefx#18116.

Commit migrated from https://github.com/dotnet/corefx/commit/711f785f072c8131b9d49792eeab02d2d55be662
2017-06-27 14:34:03 -04:00
Stephen Toub cb34ae9b7d Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/eb9e3e618bc24dad15680362d58324ac1bdba374
2017-06-26 23:03:19 -04:00
Stephen Toub 396d3b5f6d Fix incorrect assert in WriteBytesSlowAsync
Commit migrated from https://github.com/dotnet/corefx/commit/4ad64c90c5b441e8d4779b6846d7aee1f5b464c2
2017-06-26 23:01:43 -04:00
Stephen Toub 04842ec6d6 Address some previous PR feedback
- Change HttpConnectionKey's hash code
- Avoid redirectCount overflow in SendAsync
- Handle response HTTP versions other than 1.1
- Use GetHeaderValue from Windows implementation


Commit migrated from https://github.com/dotnet/corefx/commit/dd5208c4c3e8f49b895fbe32282975e3dd283a7e
2017-06-26 23:01:42 -04:00
Stephen Toub a67a5436e9 Add faster WriteStringAsync
Commit migrated from https://github.com/dotnet/corefx/commit/d1466be18dab6d5c68a3d33727a2cb5fa1ac475e
2017-06-26 23:01:42 -04:00
Stephen Toub eb04210756 Remove throw when can't add header
Match CurlHandler and WinHttpHandler behaviors


Commit migrated from https://github.com/dotnet/corefx/commit/4def2c0b045feba5f3ec317ab3ae8b29caf76e7b
2017-06-26 23:01:42 -04:00
Stephen Toub 2a44f0736d Clean up ManagedHandler class a bit
- Add some arg validation to match existing CurlHandler
- Change some names to be consistent with CurlHandler
- Use expression-bodied syntax in a few places
- Ensure only one handler is published in the face of race conditions


Commit migrated from https://github.com/dotnet/corefx/commit/56e96a6841f1bdef5756dc886ec24028fd9576ee
2017-06-26 23:01:42 -04:00
Stephen Toub 9ed67baf58 Replace some hardcoded strings in the implementation
Commit migrated from https://github.com/dotnet/corefx/commit/054c6ab6895ccce97e0e9d980503fa12d0d21594
2017-06-26 23:01:42 -04:00
Stephen Toub 30740c9062 Rename CopyFromBufferAsync to end in Async
Commit migrated from https://github.com/dotnet/corefx/commit/edc02ea7140e0b5571563f6af98c222fb32a9da7
2017-06-26 23:01:42 -04:00
Stephen Toub 44300123ff FlushAsync need not be an async method
Once we pass the _writeOffset to WriteAsync, we've copied it, so we can immediately zero out the field and just return the WriteAsync task, rather than wrapping it in another async method.


Commit migrated from https://github.com/dotnet/corefx/commit/10b23970906ac7eacb4e05898bb9fc42b291fa94
2017-06-26 23:01:42 -04:00
Stephen Toub df60499619 Remove some overhead from FillAsync
FillAsync does a single async read, and the only thing it does after that is updating the stored length.  We can use ContinueWith rather than async/await in this case to avoid a small amount of overhead.


Commit migrated from https://github.com/dotnet/corefx/commit/47f14c20143f4252afc3e60550b79be1e48e1386
2017-06-26 23:01:42 -04:00
Stephen Toub e51b594c04 Remove intermediate async method when no proxy Uri
Commit migrated from https://github.com/dotnet/corefx/commit/16ffd461934b9b494bab050f55cc51943c985d4c
2017-06-26 23:01:42 -04:00
Stephen Toub bd2ffdb8cf Remove async yielding method from HttpConnectionHandler
When we get a connection from the pool, we don't need the intermediary async method.


Commit migrated from https://github.com/dotnet/corefx/commit/63d0493d0276bb32db2634f52329b19f68136922
2017-06-26 23:01:42 -04:00
Stephen Toub d803ddb29a Use cached header names and reason phrases
Commit migrated from https://github.com/dotnet/corefx/commit/b6710956a12c702f72477d6cda4dd5db797977a2
2017-06-26 23:01:42 -04:00
Stephen Toub f03d1ab921 Fixed !!_disposed typos
Commit migrated from https://github.com/dotnet/corefx/commit/8e32964318e081d727771d6302d1407767875e71
2017-06-26 23:01:42 -04:00
Stephen Toub f2ca7ef4ff Add WriteAsciiStringAsync helper
We can avoid per-char ASCII checks for cases where the string is already known to be ASCII only.


Commit migrated from https://github.com/dotnet/corefx/commit/aecd8c20ddf3dbd47d4622120498ae50a5917468
2017-06-26 23:01:42 -04:00
Stephen Toub 2264071d51 Avoid setting Host header
Doing so incurs a variety of allocations.  Better to just output the header if we need to.


Commit migrated from https://github.com/dotnet/corefx/commit/63e5cd798774343da38256c9f0069a20f9c1a15f
2017-06-26 23:01:42 -04:00
David Shulman 554f8f2fbd Remove outdated TODO in HttpClientHandler for UAP
The current behavior for .NET Core (Windows, *Nix, and UAP) is to use a
default HTTP version if none or an illegal version is specified.

On .NET Framework, an exception is thrown in these cases, "Only HTTP/1.0
and HTTP/1.1 version requests are currently supported." This error
message wouldn't make sense now anyways since HTTP/2 is supported in
.NET Core. So, it is better to use a default version than to throw an
exception.

This difference between .NET Core and .NET Framework will be document
here:
https://github.com/dotnet/corefx/wiki/ApiCompat

Fixes dotnet/corefx#7878


Commit migrated from https://github.com/dotnet/corefx/commit/693f6dacd3b60af2b2ace76872e5644dcc03b68c
2017-06-26 15:36:58 -07:00
David Shulman 33911341ca HttpClienthandler code cleanup for UAP (dotnet/corefx#21528)
This file had never been formatted according to CoreFx style guidelines
when the code was first ported into GitHub.

Now that we are doing NETStandard2.0 work, I wanted to clean up this
file to avoid distractions as I add features.

Commit migrated from https://github.com/dotnet/corefx/commit/e92a6a087acb32f37fa7628cc92c76903733f73d
2017-06-25 17:52:40 -04:00
David Shulman 15fcaa332b Address PR feedback
Commit migrated from https://github.com/dotnet/corefx/commit/b690cd329dba0da32824b29eeb3945d6d11f6085
2017-06-24 21:20:40 -07:00
David Shulman 07b1b1c311 Fix some HttpClientHandler properties for UAP
Due to platform differences on UAP and the current use of WinRT APIs to
implement that HTTP stack, a few properties won't have the same defaults
or behavior.

Similar to the decision made in PR dotnet/corefx#21403, don't throw PNSE. Instead
just no-op.

Fixes dotnet/corefx#18036 dotnet/corefx#17812


Commit migrated from https://github.com/dotnet/corefx/commit/0de066e0bc3b67b6bc6fd1db26abea2cda1ce4d9
2017-06-24 14:14:45 -07:00
Stephen Toub d27e97ef82 Merge pull request dotnet/corefx#21458 from stephentoub/cleanup_writes
Some more miscellaneous ManagedHandler cleanup

Commit migrated from https://github.com/dotnet/corefx/commit/7d211a8d432ed70243b1fa8d627a64483d99e226
2017-06-23 21:31:44 -04:00
Hugh Bellamy 7cbcd5ed85 Convert most Assert.Throws<ArgumentException> without param name to AssertExtensions (dotnet/corefx#21455)
* Registry

* Collections

* ComponentModel

* Configuration

* Data

* Globalization

* Drawing

* Diagnostics

* IO

* Linq

* Add System.Net param names in tests

* Move ArgumentExceptions in System.Private.Xml to AssertExtensions

* Add System.Reflection.* ArgumentException param names

* Add param names for System.Runtime* ArgumentExceptions

* Add ArgumentException param names to System.Security.*

* Add ArgumentException param names to System.Text.*

* Add param names to ArgumentExceptions in misc projects

* Add System.Threading.* ArgumentException param names

* Fix missing files

* Fixes for unix and netfx

* Fix more failures and revert a IdnaConformance tests to avoid merge conflicts with dotnet/corefx#21463


Commit migrated from https://github.com/dotnet/corefx/commit/59915687bb261efeae70565d0ca8990ac45ceb9c
2017-06-23 12:33:47 -07:00
Stephen Toub 3b9ae05401 Clean up some unnecessary ValueTask<bool>s
These can just use Task and Task.CompletedTask.  Also fix some throws that should return a faulted task.


Commit migrated from https://github.com/dotnet/corefx/commit/81ca4a02a0556509bfa29b470a5d79fee0618849
2017-06-23 10:27:56 -04:00
Stephen Toub 7db5721a22 Clean up individual WriteCharAsync calls
- No need to validate that chars are ASCII when we know they are
- We can output strings just by copying bytes rather than processing individual chars


Commit migrated from https://github.com/dotnet/corefx/commit/3dc7379064780a0e95af87b0a425ba0258f2892e
2017-06-23 10:27:56 -04:00
David Shulman 21b6b7e235 Fix HttpClientHandler PreAuthenticate property for UAP (dotnet/corefx#21403)
The HttpClientHandler for UAP does not properly implement the PreAuthenticate
property. This is because on UAP, HttpClientHandler is built on the WinRT
APIs which in turn are built on WinInet. And WinInet always uses authentication
caching internally and this results in the net effect of PreAuthenticate always
being "true".

The default for .NET Framework and .NET Core (non-UAP) is "false".

When this property was first added to .NET Core 1.1, the UAP version defaulted
to true and the setter would throw PNSE.

As part of .NET Core 2.0, API surface for networking APIs was expanded. This
resulted in HttpWebRequest exposing and implementing a "PreAuthenticate" property,
which is what it has historically done in .NET Framework. On .NET Core, HttpWebRequest
is built on top of HttpClient. And so, HttpWebRequest was enhanced in .NET Core 2.0
to set the default of PreAuthenticate to false. But this later caused the PNSE
exception to surface and this exception was caught in UWP app-compat testing.
Essentially, we had now created the default HttpWebRequest to always throw an
exception.

So, in PR dotnet/corefx#18105, the PNSE in HttpClientHandler.PreAuthenticate was commented out
and thus the setter became a no-op.

This PR basically acknowledges this situation and removes the TODO from this change.
Since there is no good way to implement the actual HttpClientHandler.PreAuthenticate
property, I left the getter default to return "true" which is closer to reality of
what happens on UAP (even though this default value is different from .NET Framework
or the rest of .NET Core). And, in terms of the setter for the property, I opted to
leave it as a no-op. This seems like the best compromise outcome for now and will
generate less distraction for developers rather than throwing an exception all the
time.

The rest of this PR moves the ActiveIssue's from the class level to the method level
as part of eventually solving all of them. In addition, I added a new test case to
validate the HttpClientHandler constructor defaults that are different on the UAP
platform.

Fixes dotnet/corefx#18104

Commit migrated from https://github.com/dotnet/corefx/commit/c3b2f15d90972a5607415582681584965f16c01d
2017-06-23 05:26:07 -04:00
Stephen Toub 400480d0cb Optimize several range checks
Commit migrated from https://github.com/dotnet/corefx/commit/566a1166a167dce5b652ead0191ff87b78a36575
2017-06-22 23:14:05 -04:00