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
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
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
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/ApiCompatFixesdotnet/corefx#19642Fixesdotnet/corefx#21510
Commit migrated from https://github.com/dotnet/corefx/commit/2c33453f3e4064c75d404c6f3590ddf00a377d10
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
- 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
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/ApiCompatFixesdotnet/corefx#7878
Commit migrated from https://github.com/dotnet/corefx/commit/693f6dacd3b60af2b2ace76872e5644dcc03b68c
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
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.
Fixesdotnet/corefx#18104
Commit migrated from https://github.com/dotnet/corefx/commit/c3b2f15d90972a5607415582681584965f16c01d
- Apply IDE simplifications for things like null checks during assignments
- Fix GetOrAdd calls to only allocate if necessary
- Use throw expressions in a few places
- Add some readonlys to fields
- Change some .Waits to .GetAwaiter().GetResult()s
- Remove some unnecessary abstract overrides
- Remove some unnecessary usings
Commit migrated from https://github.com/dotnet/corefx/commit/dc01adf473ae5031be436808bf4b310c364c4268
The primary purpose of the PR is to get the code into the repo (not enabled by default), so most PR feedback is being left for subsequent PRs. However, this commit addresses the feedback deemed imperative to fix prior to initial merge.
Commit migrated from https://github.com/dotnet/corefx/commit/5c86b5e5e1a6896e0be396a6422e8f3ebed78648