diff options
author | Martin Baulig <mabaul@microsoft.com> | 2019-02-01 16:09:30 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-02-01 16:09:30 +0300 |
commit | 2f411750acfd2132f9b4970ef8cf11d9a0f62df9 (patch) | |
tree | 9cbe04bbe431151ed38c0f2a2d9fc307d0a0a5ed /mcs/class/System.Net.Http.WebRequest | |
parent | af70768885ef3d403db534ed1bd8af798cbc80e0 (diff) |
"Imperial Red": Bring HttpClient from CoreFx (#11906)
This brings `System.Net.Http` from CoreFx.
It is currently only enabled on Desktop Mac and Linux; Mobile is coming shortly.
Diffstat (limited to 'mcs/class/System.Net.Http.WebRequest')
6 files changed, 119 insertions, 96 deletions
diff --git a/mcs/class/System.Net.Http.WebRequest/Makefile b/mcs/class/System.Net.Http.WebRequest/Makefile index 20b890747f5..deca27db3fd 100644 --- a/mcs/class/System.Net.Http.WebRequest/Makefile +++ b/mcs/class/System.Net.Http.WebRequest/Makefile @@ -4,11 +4,16 @@ include ../../build/rules.make LIBRARY = System.Net.Http.WebRequest.dll -LIB_REFS = System.Net.Http System +LIB_REFS = System.Net.Http System System.Core KEYFILE = ../msfinal.pub LIB_MCS_FLAGS = -TEST_MCS_FLAGS = -TEST_LIB_REFS = System.Net.Http +TEST_MCS_FLAGS = -d:WEBREQUEST_HANDLER +TEST_LIB_REFS = System System.Core System.Net.Http System.Net.Http.WebRequest + +ifndef SOCKETSHTTPHANDLER +TEST_MCS_FLAGS += -d:LEGACY_HTTPCLIENT +LIB_MCS_FLAGS += -d:LEGACY_HTTPCLIENT +endif include ../../build/library.make diff --git a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.csproj b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.csproj index 470a9696c5d..45990a9e1cd 100644 --- a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.csproj +++ b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.csproj @@ -51,15 +51,25 @@ <!-- @BUILT_SOURCES@ -->
<!--Common files-->
<ItemGroup>
+ <Compile Include="..\..\build\common\Consts.cs" />
<Compile Include="..\..\build\common\MonoTODOAttribute.cs" />
+ <Compile Include="..\System.Net.Http\MonoWebRequestHandler.cs" />
<Compile Include="Assembly\AssemblyInfo.cs" />
<Compile Include="System.Net.Http.WebRequest\WebRequestHandler.cs" />
+ <ProjectReference Include="$(SolutionDir)\msvc\scripts\genconsts.csproj">
+ <Name>genconsts</Name>
+ <Project>{702AE2C0-71DD-4112-9A06-E4FABCA59986}</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ <CopyToOutputDirectory>Never</CopyToOutputDirectory>
+ <Private>false</Private>
+ </ProjectReference>
</ItemGroup>
<!--End of common files-->
<!-- @ALL_SOURCES@ -->
<ItemGroup>
<ProjectReference Include="../System.Net.Http/System.Net.Http.csproj" />
<ProjectReference Include="../System/System.csproj" />
+ <ProjectReference Include="../System.Core/System.Core.csproj" />
<ProjectReference Include="../corlib/corlib.csproj" />
</ItemGroup>
<!-- @ALL_REFERENCES@ -->
diff --git a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.dll.sources b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.dll.sources index e61f1b57ccb..a0cf780c0f4 100644 --- a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.dll.sources +++ b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest.dll.sources @@ -1,3 +1,5 @@ +../../build/common/Consts.cs ../../build/common/MonoTODOAttribute.cs Assembly/AssemblyInfo.cs System.Net.Http.WebRequest/WebRequestHandler.cs +../System.Net.Http/MonoWebRequestHandler.cs
\ No newline at end of file diff --git a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest/WebRequestHandler.cs b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest/WebRequestHandler.cs index 79b64375652..11dff0fcad6 100644 --- a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest/WebRequestHandler.cs +++ b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest/WebRequestHandler.cs @@ -24,141 +24,83 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Linq; +using System.Threading; using System.Net.Cache; using System.Net.Security; using System.Security.Principal; using System.Security.Cryptography.X509Certificates; +using System.Collections.Generic; namespace System.Net.Http { public class WebRequestHandler : HttpClientHandler { - bool allowPipelining; - RequestCachePolicy cachePolicy; - AuthenticationLevel authenticationLevel; - TimeSpan continueTimeout; - TokenImpersonationLevel impersonationLevel; - int maxResponseHeadersLength; - int readWriteTimeout; - RemoteCertificateValidationCallback serverCertificateValidationCallback; - bool unsafeAuthenticatedConnectionSharing; - X509CertificateCollection clientCertificates; + MonoWebRequestHandler handler; + + bool disposed; public WebRequestHandler () + : this (new MonoWebRequestHandler ()) { - allowPipelining = true; - authenticationLevel = AuthenticationLevel.MutualAuthRequested; - cachePolicy = System.Net.WebRequest.DefaultCachePolicy; - continueTimeout = TimeSpan.FromMilliseconds (350); - impersonationLevel = TokenImpersonationLevel.Delegation; - maxResponseHeadersLength = HttpWebRequest.DefaultMaximumResponseHeadersLength; - readWriteTimeout = 300000; - serverCertificateValidationCallback = null; - unsafeAuthenticatedConnectionSharing = false; - clientCertificates = new X509CertificateCollection(); + } + + WebRequestHandler (MonoWebRequestHandler handler) + : base (handler) + { + this.handler = handler; } public bool AllowPipelining { - get { return allowPipelining; } - set { - EnsureModifiability (); - allowPipelining = value; - } + get => handler.AllowPipelining; + set => handler.AllowPipelining = value; } public RequestCachePolicy CachePolicy { - get { return cachePolicy; } - set { - EnsureModifiability (); - cachePolicy = value; - } + get => handler.CachePolicy; + set => handler.CachePolicy = value; } public AuthenticationLevel AuthenticationLevel { - get { return authenticationLevel; } - set { - EnsureModifiability (); - authenticationLevel = value; - } - } - - public X509CertificateCollection ClientCertificates { - get { - if (this.ClientCertificateOptions != ClientCertificateOption.Manual) { - throw new InvalidOperationException("The ClientCertificateOptions property must be set to 'Manual' to use this property."); - } - - return clientCertificates; - } + get => handler.AuthenticationLevel; + set => handler.AuthenticationLevel = value; } [MonoTODO] public TimeSpan ContinueTimeout { - get { return continueTimeout; } - set { - EnsureModifiability (); - continueTimeout = value; - } + get => handler.ContinueTimeout; + set => handler.ContinueTimeout = value; } public TokenImpersonationLevel ImpersonationLevel { - get { return impersonationLevel; } - set { - EnsureModifiability (); - impersonationLevel = value; - } - } - - public int MaxResponseHeadersLength { - get { return maxResponseHeadersLength; } - set { - EnsureModifiability (); - maxResponseHeadersLength = value; - } + get => handler.ImpersonationLevel; + set => handler.ImpersonationLevel = value; } public int ReadWriteTimeout { - get { return readWriteTimeout; } - set { - EnsureModifiability (); - readWriteTimeout = value; - } + get => handler.ReadWriteTimeout; + set => handler.ReadWriteTimeout = value; } public RemoteCertificateValidationCallback ServerCertificateValidationCallback { - get { return serverCertificateValidationCallback; } - set { - EnsureModifiability (); - serverCertificateValidationCallback = value; - } + get => handler.ServerCertificateValidationCallback; + set => handler.ServerCertificateValidationCallback = value; } public bool UnsafeAuthenticatedConnectionSharing { - get { return unsafeAuthenticatedConnectionSharing; } - set { - EnsureModifiability (); - unsafeAuthenticatedConnectionSharing = value; - } + get => handler.UnsafeAuthenticatedConnectionSharing; + set => handler.UnsafeAuthenticatedConnectionSharing = value; } - internal override HttpWebRequest CreateWebRequest (HttpRequestMessage request) + protected override void Dispose (bool disposing) { - HttpWebRequest wr = base.CreateWebRequest (request); - - wr.Pipelined = allowPipelining; - wr.AuthenticationLevel = authenticationLevel; - wr.CachePolicy = cachePolicy; - wr.ImpersonationLevel = impersonationLevel; - wr.MaximumResponseHeadersLength = maxResponseHeadersLength; - wr.ReadWriteTimeout = readWriteTimeout; - wr.UnsafeAuthenticatedConnectionSharing = unsafeAuthenticatedConnectionSharing; - wr.ServerCertificateValidationCallback = serverCertificateValidationCallback; - - if (this.ClientCertificateOptions == ClientCertificateOption.Manual) { - wr.ClientCertificates = clientCertificates; + if (disposing && !disposed) { + Volatile.Write (ref disposed, true); + handler.Dispose (); + handler = null; } - return wr; + base.Dispose (disposing); } } } diff --git a/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest_test.dll.sources b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest_test.dll.sources new file mode 100644 index 00000000000..63d6308416f --- /dev/null +++ b/mcs/class/System.Net.Http.WebRequest/System.Net.Http.WebRequest_test.dll.sources @@ -0,0 +1,37 @@ +../../test-helpers/NetworkHelpers.cs +HttpClientTestHelpers.cs +../../System.Net.Http/Test/System.Net.Http/DelegatingHandlerTest.cs +../../System.Net.Http/Test/System.Net.Http/ByteArrayContentTest.cs +../../System.Net.Http/Test/System.Net.Http/FormUrlEncodedContentTest.cs +../../System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs +../../System.Net.Http/Test/System.Net.Http/HttpClientTest.cs +../../System.Net.Http/Test/System.Net.Http/HttpMethodTest.cs +../../System.Net.Http/Test/System.Net.Http/HttpRequestMessageTest.cs +../../System.Net.Http/Test/System.Net.Http/HttpResponseMessageTest.cs +../../System.Net.Http/Test/System.Net.Http/MultipartContentTest.cs +../../System.Net.Http/Test/System.Net.Http/MultipartFormDataContentTest.cs +../../System.Net.Http/Test/System.Net.Http/StreamContentTest.cs +../../System.Net.Http/Test/System.Net.Http/StringContentTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/AuthenticationHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/CacheControlHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/ContentDispositionHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/ContentRangeHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/EntityTagHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/HttpHeadersTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/HttpHeaderValueCollection.cs +../../System.Net.Http/Test/System.Net.Http.Headers/HttpRequestHeadersTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/MediaTypeHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/MediaTypeWithQualityHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/NameValueHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/NameValueWithParametersHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/ProductHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/ProductInfoHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/RangeConditionHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/RangeHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/RangeItemHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/RetryConditionHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/StringWithQualityHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/TransferCodingHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/TransferCodingWithQualityHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/ViaHeaderValueTest.cs +../../System.Net.Http/Test/System.Net.Http.Headers/WarningHeaderValueTest.cs diff --git a/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs b/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs new file mode 100644 index 00000000000..47b1410bf2f --- /dev/null +++ b/mcs/class/System.Net.Http.WebRequest/Test/HttpClientTestHelpers.cs @@ -0,0 +1,27 @@ +using System; +using System.Reflection; +using System.Net.Http; + +namespace MonoTests.System.Net.Http +{ + static class HttpClientTestHelpers + { +#if LEGACY_HTTPCLIENT + internal static bool UsingSocketsHandler => false; +#else + internal static bool UsingSocketsHandler => true; +#endif + + internal static bool IsSocketsHandler (HttpClientHandler handler) => false; + + internal static HttpClient CreateHttpClient () + { + return new HttpClient (CreateHttpClientHandler ()); + } + + internal static HttpClientHandler CreateHttpClientHandler () + { + return new WebRequestHandler (); + } + } +} |