Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -2,6 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.2.0</AssemblyVersion>
<AssemblyVersion>4.0.3.0</AssemblyVersion>
<AssemblyKey>MSFT</AssemblyKey>
</PropertyGroup>
</Project>

View File

@ -3,12 +3,18 @@
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.Net.Http.WinHttpHandler.csproj">
<SupportedFramework>net46;netcoreapp1.0</SupportedFramework>
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.Net.Http.WinHttpHandler.csproj" />
<NotSupportedOnTargetFramework Include="netcore50">
<PackageTargetRuntime>win</PackageTargetRuntime>
</NotSupportedOnTargetFramework>
<HarvestIncludePaths Include="lib/net46;runtimes/win/lib/net46" />
<HarvestIncludePaths Include="ref/netstandard1.3">
<SupportedFramework>netcore50</SupportedFramework>
</HarvestIncludePaths>
<HarvestIncludePaths Include="runtimes/win/lib/netstandard1.3" />
<HarvestIncludePaths Include="runtimes/unix/lib/netstandard1.3">
<!-- package unix impl (platform not supported) as RID agnostic -->
<TargetPath>lib/netstandard1.3</TargetPath>
</HarvestIncludePaths>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<BuildConfigurations>
netstandard-Windows_NT;
netstandard-Unix;
netstandard;
netfx-Windows_NT;
</BuildConfigurations>
</PropertyGroup>

View File

@ -1,26 +0,0 @@
kernel32.dll!GetModuleHandleW
winhttp.dll!WinHttpAddRequestHeaders
winhttp.dll!WinHttpCloseHandle
winhttp.dll!WinHttpConnect
winhttp.dll!WinHttpGetIEProxyConfigForCurrentUser
winhttp.dll!WinHttpGetProxyForUrl
winhttp.dll!WinHttpOpen
winhttp.dll!WinHttpOpenRequest
winhttp.dll!WinHttpQueryAuthSchemes
winhttp.dll!WinHttpQueryDataAvailable
winhttp.dll!WinHttpQueryHeaders
winhttp.dll!WinHttpQueryOption
winhttp.dll!WinHttpReadData
winhttp.dll!WinHttpReceiveResponse
winhttp.dll!WinHttpSendRequest
winhttp.dll!WinHttpSetCredentials
winhttp.dll!WinHttpSetOption
winhttp.dll!WinHttpSetStatusCallback
winhttp.dll!WinHttpSetTimeouts
winhttp.dll!WinHttpWebSocketClose
winhttp.dll!WinHttpWebSocketCompleteUpgrade
winhttp.dll!WinHttpWebSocketQueryCloseStatus
winhttp.dll!WinHttpWebSocketReceive
winhttp.dll!WinHttpWebSocketSend
winhttp.dll!WinHttpWebSocketShutdown
winhttp.dll!WinHttpWriteData

View File

@ -121,4 +121,7 @@
<data name="net_http_content_stream_already_read" xml:space="preserve">
<value>The stream was already consumed. It cannot be read again.</value>
</data>
<data name="PlatformNotSupported_WinHttpHandler" xml:space="preserve">
<value>WinHttpHandler is only supported on .NET Framework and .NET Core runtimes on Windows. It is not supported for Windows Store Applications (UWP) or Unix platforms.</value>
</data>
</root>

View File

@ -6,13 +6,15 @@
<ProjectGuid>{F75E3008-0562-42DF-BE72-C1384F12157E}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>System.Net.Http.WinHttpHandler</AssemblyName>
<GeneratePlatformNotSupportedAssembly Condition="'$(TargetsUnix)' == 'true'">true</GeneratePlatformNotSupportedAssembly>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetGroup)' == 'netstandard' AND '$(TargetsWindows)' != 'true'">SR.PlatformNotSupported_WinHttpHandler</GeneratePlatformNotSupportedAssemblyMessage>
<!-- Although we have a NS configuration, the actual UWP implementation is a shim over WinRT: so just validate against OneCore -->
<UWPCompatible>false</UWPCompatible>
<IncludeDllSafeSearchPathAttribute>true</IncludeDllSafeSearchPathAttribute>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
<Import Project="System.Net.Http.WinHttpHandler.msbuild" Condition="'$(TargetsWindows)' == 'true'" />
@ -57,6 +59,7 @@
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.Handles" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Security.Cryptography.Encoding" />
<Reference Include="System.Security.Cryptography.X509Certificates" />
<Reference Include="System.Text.Encoding" />
<Reference Include="System.Threading" />

View File

@ -15,7 +15,6 @@
<CompileItem Include="$(CommonPath)\Interop\Windows\winhttp\Interop.winhttp.cs" />
<CompileItem Include="$(CommonPath)\System\CharArrayHelpers.cs" />
<CompileItem Include="$(CommonPath)\System\StringExtensions.cs" />
<CompileItem Include="$(CommonPath)\System\Diagnostics\ExceptionExtensions.cs" />
<CompileItem Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.cs" />
<CompileItem Include="$(CommonPath)\System\Net\HttpKnownHeaderNames.TryGetHeaderName.cs" />
<CompileItem Include="$(CommonPath)\System\Net\UriScheme.cs" />
@ -23,6 +22,7 @@
<CompileItem Include="$(CommonPath)\System\Net\Http\HttpHandlerDefaults.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Http\NoWriteNoSeekStreamContent.cs" />
<CompileItem Include="$(CommonPath)\System\Net\Http\WinHttpException.cs" />
<CompileItem Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs" />
<CompileItem Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs" />
<CompileItem Include="$(CommonPath)\System\Threading\Tasks\TaskToApm.cs" />
<CompileItem Include="$(MSBuildThisFileDirectory)\System\Net\Http\WinHttpAuthHelper.cs" />

View File

@ -4,6 +4,7 @@
using System.Net.Security;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace System.Net.Http
@ -11,6 +12,7 @@ namespace System.Net.Http
internal static class WinHttpCertificateHelper
{
private const string ClientAuthenticationOID = "1.3.6.1.5.5.7.3.2";
private static readonly Oid s_serverAuthOid = new Oid("1.3.6.1.5.5.7.3.1");
// TODO: Issue #2165. Merge with similar code used in System.Net.Security move to Common/src//System/Net.
public static void BuildChain(
@ -28,6 +30,9 @@ namespace System.Net.Http
chain.ChainPolicy.RevocationMode =
checkCertificateRevocationList ? X509RevocationMode.Online : X509RevocationMode.NoCheck;
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
// Authenticate the remote party: (e.g. when operating in client mode, authenticate the server).
chain.ChainPolicy.ApplicationPolicy.Add(s_serverAuthOid);
if (!chain.Build(certificate))
{
sslPolicyErrors |= SslPolicyErrors.RemoteCertificateChainErrors;
@ -42,7 +47,7 @@ namespace System.Net.Http
var eppStruct = new Interop.Crypt32.SSL_EXTRA_CERT_CHAIN_POLICY_PARA();
eppStruct.cbSize = (uint)Marshal.SizeOf<Interop.Crypt32.SSL_EXTRA_CERT_CHAIN_POLICY_PARA>();
eppStruct.dwAuthType = Interop.Crypt32.AuthType.AUTHTYPE_CLIENT;
eppStruct.dwAuthType = Interop.Crypt32.AuthType.AUTHTYPE_SERVER;
cppStruct.pvExtraPolicyPara = &eppStruct;

View File

@ -87,7 +87,7 @@ namespace System.Net.Http
private TimeSpan _sendTimeout = TimeSpan.FromSeconds(30);
private TimeSpan _receiveHeadersTimeout = TimeSpan.FromSeconds(30);
private TimeSpan _receiveDataTimeout = TimeSpan.FromSeconds(30);
private int _maxResponseHeadersLength = 64 * 1024;
private int _maxResponseHeadersLength = HttpHandlerDefaults.DefaultMaxResponseHeadersLength;
private int _maxResponseDrainSize = 64 * 1024;
private IDictionary<String, Object> _properties; // Only create dictionary when required.
private volatile bool _operationStarted;
@ -1173,7 +1173,7 @@ namespace System.Net.Http
private void SetRequestHandleBufferingOptions(SafeWinHttpHandle requestHandle)
{
uint optionData = (uint)_maxResponseHeadersLength;
uint optionData = (uint)(_maxResponseHeadersLength * 1024);
SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_HEADER_SIZE, ref optionData);
optionData = (uint)_maxResponseDrainSize;
SetWinHttpOption(requestHandle, Interop.WinHttp.WINHTTP_OPTION_MAX_RESPONSE_DRAIN_SIZE, ref optionData);
@ -1249,7 +1249,7 @@ namespace System.Net.Http
// If the exception was due to the cancellation token being canceled, throw cancellation exception.
state.Tcs.TrySetCanceled(state.CancellationToken);
}
else if (ex is WinHttpException || ex is IOException)
else if (ex is WinHttpException || ex is IOException || ex is InvalidOperationException)
{
// Wrap expected exceptions as HttpRequestExceptions since this is considered an error during
// execution. All other exception types, including ArgumentExceptions and ProtocolViolationExceptions
@ -1337,11 +1337,16 @@ namespace System.Net.Http
0,
state.ToIntPtr()))
{
int lastError = Marshal.GetLastWin32Error();
Debug.Assert((unchecked((int)lastError) != Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER &&
unchecked((int)lastError) != unchecked((int)0x80090321)), // SEC_E_BUFFER_TOO_SMALL
$"Unexpected async error in WinHttpRequestCallback: {unchecked((int)lastError)}");
// Dispose (which will unpin) the state object. Since this failed, WinHTTP won't associate
// our context value (state object) to the request handle. And thus we won't get HANDLE_CLOSING
// notifications which would normally cause the state object to be unpinned and disposed.
state.Dispose();
WinHttpException.ThrowExceptionUsingLastError();
throw WinHttpException.CreateExceptionUsingError(lastError);
}
}

View File

@ -305,9 +305,13 @@ namespace System.Net.Http
Debug.Assert(state != null, "OnRequestError: state is null");
Exception innerException = WinHttpException.CreateExceptionUsingError((int)asyncResult.dwError);
Debug.Assert((unchecked((int)asyncResult.dwError) != Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER &&
unchecked((int)asyncResult.dwError) != unchecked((int)0x80090321)), // SEC_E_BUFFER_TOO_SMALL
$"Unexpected async error in WinHttpRequestCallback: {unchecked((int)asyncResult.dwError)}, WinHttp API: {unchecked((uint)asyncResult.dwResult.ToInt32())}");
switch ((uint)asyncResult.dwResult.ToInt32())
Exception innerException = WinHttpException.CreateExceptionUsingError(unchecked((int)asyncResult.dwError));
switch (unchecked((uint)asyncResult.dwResult.ToInt32()))
{
case Interop.WinHttp.API_SEND_REQUEST:
state.LifecycleAwaitable.SetException(innerException);

View File

@ -195,6 +195,11 @@ namespace System.Net.Http
private Task InternalWriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
{
if (count == 0)
{
return Task.CompletedTask;
}
return _chunkedMode ?
InternalWriteChunkedModeAsync(buffer, offset, count, token) :
InternalWriteDataAsync(buffer, offset, count, token);
@ -206,6 +211,7 @@ namespace System.Net.Http
// and instead use the 'Transfer-Encoding: chunked' header. The caller is still required to encode the
// request body according to chunking rules.
Debug.Assert(_chunkedMode);
Debug.Assert(count > 0);
string chunkSizeString = String.Format("{0:x}\r\n", count);
byte[] chunkSize = Encoding.UTF8.GetBytes(chunkSizeString);
@ -218,13 +224,8 @@ namespace System.Net.Http
private Task<bool> InternalWriteDataAsync(byte[] buffer, int offset, int count, CancellationToken token)
{
Debug.Assert(count >= 0);
if (count == 0)
{
return Task.FromResult<bool>(true);
}
Debug.Assert(count > 0);
// TODO (Issue 2505): replace with PinnableBufferCache.
if (!_cachedSendPinnedBuffer.IsAllocated || _cachedSendPinnedBuffer.Target != buffer)
{
@ -248,7 +249,7 @@ namespace System.Net.Http
IntPtr.Zero))
{
_state.TcsInternalWriteDataToRequestStream.TrySetException(
new IOException(SR.net_http_io_write, WinHttpException.CreateExceptionUsingLastError().InitializeStackTrace()));
new IOException(SR.net_http_io_write, WinHttpException.CreateExceptionUsingLastError()));
}
}

View File

@ -207,6 +207,11 @@ namespace System.Net.Http
private async Task<int> ReadAsyncCore(byte[] buffer, int offset, int count, CancellationToken token)
{
if (count == 0)
{
return 0;
}
_state.PinReceiveBuffer(buffer);
var ctr = token.Register(s => ((WinHttpResponseStream)s).CancelPendingResponseStreamReadOperation(), this);
_state.AsyncReadInProgress = true;

View File

@ -6,7 +6,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StringResourcesPath>../../src/Resources/Strings.resx</StringResourcesPath>
</PropertyGroup>
<!-- Help VS understand available configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
@ -37,9 +36,6 @@
<Compile Include="$(CommonPath)\System\StringExtensions.cs">
<Link>Common\System\StringExtensions.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Diagnostics\ExceptionExtensions.cs">
<Link>Common\System\Diagnostics\ExceptionExtensions.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\IO\StreamHelpers.CopyValidation.cs">
<Link>Common\System\IO\StreamHelpers.CopyValidation.cs</Link>
</Compile>
@ -70,6 +66,9 @@
<Compile Include="$(CommonPath)\System\Net\Http\WinHttpException.cs">
<Link>Common\System\Net\Http\WinHttpException.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Runtime\ExceptionServices\ExceptionStackTrace.cs">
<Link>Common\System\Runtime\ExceptionServices\ExceptionStackTrace.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Threading\Tasks\RendezvousAwaitable.cs">
<Link>Common\System\Threading\Tasks\RendezvousAwaitable.cs</Link>
</Compile>

View File

@ -42,7 +42,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
Assert.Equal(SslProtocols.None, handler.SslProtocols);
Assert.Equal(true, handler.AutomaticRedirection);
Assert.Equal(50, handler.MaxAutomaticRedirections);
Assert.Equal(DecompressionMethods.Deflate | DecompressionMethods.GZip, handler.AutomaticDecompression);
Assert.Equal(DecompressionMethods.None, handler.AutomaticDecompression);
Assert.Equal(CookieUsePolicy.UseInternalCookieStoreOnly, handler.CookieUsePolicy);
Assert.Equal(null, handler.CookieContainer);
Assert.Equal(null, handler.ServerCertificateValidationCallback);
@ -59,7 +59,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
Assert.Equal(TimeSpan.FromSeconds(30), handler.SendTimeout);
Assert.Equal(TimeSpan.FromSeconds(30), handler.ReceiveHeadersTimeout);
Assert.Equal(TimeSpan.FromSeconds(30), handler.ReceiveDataTimeout);
Assert.Equal(64 * 1024, handler.MaxResponseHeadersLength);
Assert.Equal(64, handler.MaxResponseHeadersLength);
Assert.Equal(64 * 1024, handler.MaxResponseDrainSize);
Assert.NotNull(handler.Properties);
}
@ -577,7 +577,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
}
[Fact]
public async Task SendAsync_PostNoContentObjectWithChunkedEncodingHeader_ExpectInvalidOperationException()
public async Task SendAsync_PostNoContentObjectWithChunkedEncodingHeader_ExpectHttpRequestException()
{
var handler = new WinHttpHandler();
using (var client = new HttpClient(handler))
@ -587,7 +587,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
var request = new HttpRequestMessage(HttpMethod.Post, TestServer.FakeServerEndpoint);
await Assert.ThrowsAsync<InvalidOperationException>(() => client.SendAsync(request));
await Assert.ThrowsAsync<HttpRequestException>(() => client.SendAsync(request));
}
}