You've already forked linux-packaging-mono
Imported Upstream version 6.4.0.137
Former-commit-id: 943baa9f16a098c33e129777827f3a9d20da00d6
This commit is contained in:
parent
e9207cf623
commit
ef583813eb
@@ -7,7 +7,7 @@ ASSEMBLY = System.Net.Http.FunctionalTests
|
||||
XTEST_LIB_REFS = System System.Core Facades/System.Threading.Tasks
|
||||
USE_XTEST_REMOTE_EXECUTOR = YES
|
||||
|
||||
XTEST_LIB_FLAGS = /resource:../TestData/testservereku.contoso.com.pfx
|
||||
XTEST_LIB_FLAGS = /resource:../../System/Test/TestData/testservereku.contoso.com.pfx
|
||||
|
||||
the_assembly = $(topdir)/class/lib/$(PROFILE_DIRECTORY)/System.Net.Http.dll
|
||||
|
||||
|
||||
10
mcs/class/System.Net.Http/HttpClient.DefaultHandler.cs
Normal file
10
mcs/class/System.Net.Http/HttpClient.DefaultHandler.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace System.Net.Http
|
||||
{
|
||||
partial class HttpClient
|
||||
{
|
||||
static HttpMessageHandler CreateDefaultHandler()
|
||||
{
|
||||
return new HttpClientHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,8 @@ namespace System.Net.Http
|
||||
partial class HttpClientHandler : HttpMessageHandler
|
||||
{
|
||||
static IMonoHttpClientHandler CreateDefaultHandler () => new MonoWebRequestHandler ();
|
||||
|
||||
// NS2.1:
|
||||
public static System.Func<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator => throw new PlatformNotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
148
mcs/class/System.Net.Http/HttpClientHandler.wasm.cs
Normal file
148
mcs/class/System.Net.Http/HttpClientHandler.wasm.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
public partial class HttpClientHandler : HttpMessageHandler
|
||||
{
|
||||
HttpMessageHandler wasmHandler;
|
||||
|
||||
public HttpClientHandler () : this (HttpClient.CreateDefaultHandler ()) { }
|
||||
|
||||
HttpClientHandler (HttpMessageHandler wasmHandler)
|
||||
{
|
||||
this.wasmHandler = wasmHandler;
|
||||
}
|
||||
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (disposing) {
|
||||
if (wasmHandler != null) {
|
||||
wasmHandler.Dispose ();
|
||||
wasmHandler = null;
|
||||
}
|
||||
}
|
||||
base.Dispose (disposing);
|
||||
}
|
||||
|
||||
const string EXCEPTION_MESSAGE = "System.Net.Http.HttpClientHandler is not supported on the current platform.";
|
||||
|
||||
public virtual bool SupportsAutomaticDecompression => false;
|
||||
|
||||
public virtual bool SupportsProxy => false;
|
||||
|
||||
public virtual bool SupportsRedirectConfiguration => false;
|
||||
|
||||
public bool UseCookies {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public CookieContainer CookieContainer {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public ClientCertificateOption ClientCertificateOptions {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public X509CertificateCollection ClientCertificates {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public bool CheckCertificateRevocationList {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public SslProtocols SslProtocols {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public DecompressionMethods AutomaticDecompression {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public bool UseProxy {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public IWebProxy Proxy {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public ICredentials DefaultProxyCredentials {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public bool PreAuthenticate {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public bool UseDefaultCredentials {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public ICredentials Credentials {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public bool AllowAutoRedirect {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public int MaxAutomaticRedirections {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public int MaxConnectionsPerServer {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public int MaxResponseHeadersLength {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public long MaxRequestContentBufferSize {
|
||||
get => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
set => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
}
|
||||
|
||||
public IDictionary<string, object> Properties => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
|
||||
protected internal override Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (wasmHandler == null)
|
||||
throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
return wasmHandler.SendAsync (request, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
mcs/class/System.Net.Http/HttpRequestMessage.Mono.cs
Normal file
18
mcs/class/System.Net.Http/HttpRequestMessage.Mono.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace System.Net.Http
|
||||
{
|
||||
partial class HttpRequestMessage
|
||||
{
|
||||
static bool IsAllowedAbsoluteUri (Uri uri)
|
||||
{
|
||||
if (!uri.IsAbsoluteUri)
|
||||
return true;
|
||||
|
||||
#if WASM
|
||||
if (uri.Scheme == "blob")
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return HttpUtilities.IsHttpUri (uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,14 +42,6 @@ TEST_MCS_FLAGS =
|
||||
|
||||
LIBRARY_WARN_AS_ERROR = yes
|
||||
|
||||
EXTRA_DISTFILES = \
|
||||
TestData/testservereku.contoso.com.pfx
|
||||
|
||||
ifndef SOCKETSHTTPHANDLER
|
||||
TEST_MCS_FLAGS += -d:LEGACY_HTTPCLIENT
|
||||
LIB_MCS_FLAGS += -d:LEGACY_HTTPCLIENT
|
||||
endif
|
||||
|
||||
SUBDIRS = FunctionalTests UnitTests
|
||||
|
||||
include ../../build/library.make
|
||||
|
||||
@@ -391,7 +391,7 @@ namespace System.Net.Http
|
||||
values = values.Where (l => l != "chunked");
|
||||
}
|
||||
|
||||
var values_formated = HeaderUtils.GetSingleHeaderString (header.Key, values);
|
||||
var values_formated = PlatformHelper.GetSingleHeaderString (header.Key, values);
|
||||
if (values_formated == null)
|
||||
continue;
|
||||
|
||||
@@ -406,11 +406,7 @@ namespace System.Net.Http
|
||||
var response = new HttpResponseMessage (wr.StatusCode);
|
||||
response.RequestMessage = requestMessage;
|
||||
response.ReasonPhrase = wr.StatusDescription;
|
||||
#if LEGACY_HTTPCLIENT
|
||||
response.Content = new StreamContent (wr.GetResponseStream (), cancellationToken);
|
||||
#else
|
||||
response.Content = new StreamContent (wr.GetResponseStream ());
|
||||
#endif
|
||||
response.Content = PlatformHelper.CreateStreamContent (wr.GetResponseStream (), cancellationToken);
|
||||
|
||||
var headers = wr.Headers;
|
||||
for (int i = 0; i < headers.Count; ++i) {
|
||||
@@ -418,7 +414,7 @@ namespace System.Net.Http
|
||||
var value = headers.GetValues (i);
|
||||
|
||||
HttpHeaders item_headers;
|
||||
if (HeaderUtils.IsContentHeader (key))
|
||||
if (PlatformHelper.IsContentHeader (key))
|
||||
item_headers = response.Content.Headers;
|
||||
else
|
||||
item_headers = response.Headers;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
static class HeaderUtils
|
||||
static class PlatformHelper
|
||||
{
|
||||
internal static bool IsContentHeader (string name)
|
||||
{
|
||||
@@ -14,5 +16,10 @@ namespace System.Net.Http
|
||||
{
|
||||
return HttpRequestHeaders.GetSingleHeaderString (name, values);
|
||||
}
|
||||
|
||||
internal static StreamContent CreateStreamContent (Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
return new StreamContent (stream, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
static class HeaderUtils
|
||||
static class PlatformHelper
|
||||
{
|
||||
internal static bool IsContentHeader (string name)
|
||||
{
|
||||
@@ -20,6 +22,11 @@ namespace System.Net.Http
|
||||
|
||||
return string.Join (separator, values);
|
||||
}
|
||||
|
||||
internal static StreamContent CreateStreamContent (Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
return new StreamContent (stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
partial class StreamContent
|
||||
{
|
||||
//
|
||||
// Workarounds for poor .NET API
|
||||
// Instead of having SerializeToStreamAsync with CancellationToken as public API. Only LoadIntoBufferAsync
|
||||
// called internally from the send worker can be cancelled and user cannot see/do it
|
||||
//
|
||||
[Obsolete ("FIXME: Please talk to Martin about this; see https://github.com/mono/mono/issues/12996.")]
|
||||
internal StreamContent (Stream content, CancellationToken cancellationToken)
|
||||
: this (content)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,9 @@ namespace System.Net.Http
|
||||
|
||||
protected internal override Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (InnerHandler == null) {
|
||||
throw new InvalidOperationException (SR.net_http_handler_not_assigned);
|
||||
}
|
||||
return InnerHandler.SendAsync (request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Net.Http {
|
||||
public partial class HttpClient {
|
||||
|
||||
public HttpClient ()
|
||||
: this (GetDefaultHandler (), true)
|
||||
{
|
||||
}
|
||||
|
||||
static HttpMessageHandler GetDefaultHandler ()
|
||||
static HttpMessageHandler CreateDefaultHandler ()
|
||||
{
|
||||
Type type = Type.GetType("Android.Runtime.AndroidEnvironment, Mono.Android");
|
||||
if (type == null)
|
||||
|
||||
@@ -338,5 +338,11 @@ namespace System.Net.Http
|
||||
return await resp.Content.ReadAsStringAsync ().ConfigureAwait (false);
|
||||
}
|
||||
}
|
||||
|
||||
// NS2.1 methods, added here while CoreFX HttpClient PR is not merged
|
||||
public Task<HttpResponseMessage> PatchAsync(string requestUri, HttpContent content) => throw new PlatformNotSupportedException();
|
||||
public Task<HttpResponseMessage> PatchAsync(string requestUri, HttpContent content, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();
|
||||
public Task<HttpResponseMessage> PatchAsync(Uri requestUri, HttpContent content) => throw new PlatformNotSupportedException();
|
||||
public Task<HttpResponseMessage> PatchAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken) => throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,11 @@ namespace System.Net.Http
|
||||
public partial class HttpClient
|
||||
{
|
||||
|
||||
#pragma warning disable 649
|
||||
private static Func<HttpMessageHandler> GetHttpMessageHandler;
|
||||
#pragma warning restore 649
|
||||
|
||||
public HttpClient()
|
||||
: this(GetDefaultHandler(), true)
|
||||
{
|
||||
}
|
||||
|
||||
static HttpMessageHandler GetDefaultHandler()
|
||||
internal static HttpMessageHandler CreateDefaultHandler()
|
||||
{
|
||||
|
||||
if (GetHttpMessageHandler == null)
|
||||
@@ -54,4 +51,4 @@ namespace System.Net.Http
|
||||
return new HttpClientHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,5 +172,8 @@ namespace System.Net.Http
|
||||
|
||||
// Only used in MonoWebRequestHandler and ignored by the other handlers.
|
||||
internal void SetWebRequestTimeout (TimeSpan timeout) => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
|
||||
|
||||
// NS2.1:
|
||||
public static System.Func<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors, bool> DangerousAcceptAnyServerCertificateValidator => throw new PlatformNotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,5 +131,8 @@ namespace System.Net.Http
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
// NS2.1:
|
||||
public static System.Net.Http.HttpMethod Patch => throw new PlatformNotSupportedException ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace System.Net.Http
|
||||
public class HttpResponseMessage : IDisposable
|
||||
{
|
||||
HttpResponseHeaders headers;
|
||||
HttpResponseHeaders trailingHeaders;
|
||||
string reasonPhrase;
|
||||
HttpStatusCode statusCode;
|
||||
Version version;
|
||||
@@ -137,5 +138,14 @@ namespace System.Net.Http
|
||||
|
||||
return sb.ToString ();
|
||||
}
|
||||
|
||||
public HttpResponseHeaders TrailingHeaders {
|
||||
get {
|
||||
if (trailingHeaders == null)
|
||||
trailingHeaders = new HttpResponseHeaders ();
|
||||
|
||||
return trailingHeaders;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
using System.Net.Http;
|
||||
|
||||
@@ -6,11 +7,18 @@ namespace MonoTests.System.Net.Http
|
||||
{
|
||||
static class HttpClientTestHelpers
|
||||
{
|
||||
#if LEGACY_HTTPCLIENT
|
||||
internal static bool UsingSocketsHandler => false;
|
||||
#else
|
||||
internal static bool UsingSocketsHandler => true;
|
||||
#endif
|
||||
static bool initialized;
|
||||
static bool usingSocketsHandler;
|
||||
static object syncLock;
|
||||
|
||||
internal static bool UsingSocketsHandler {
|
||||
get {
|
||||
LazyInitializer.EnsureInitialized (
|
||||
ref usingSocketsHandler, ref initialized, ref syncLock,
|
||||
() => typeof (HttpClient).Assembly.GetType ("System.Net.Http.SocketsHttpHandler") != null);
|
||||
return usingSocketsHandler;
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsSocketsHandler (HttpClientHandler handler) => UsingSocketsHandler;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ using System;
|
||||
using NUnit.Framework;
|
||||
using System.Net.Http;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MonoTests.System.Net.Http
|
||||
@@ -41,6 +42,13 @@ namespace MonoTests.System.Net.Http
|
||||
{
|
||||
}
|
||||
|
||||
class CustomHandler : DelegatingHandler
|
||||
{
|
||||
protected override async Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await base.SendAsync (request, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisposeTest ()
|
||||
@@ -59,5 +67,19 @@ namespace MonoTests.System.Net.Http
|
||||
} catch (ArgumentNullException) {
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async void InnerHandler_NotAssigned ()
|
||||
{
|
||||
var httpRequestMessage = new HttpRequestMessage (HttpMethod.Get, "http://contoso.com");
|
||||
var handler = new CustomHandler ();
|
||||
|
||||
var invoker = new HttpMessageInvoker (handler);
|
||||
try {
|
||||
await invoker.SendAsync (httpRequestMessage, new CancellationToken ());
|
||||
Assert.Fail ();
|
||||
} catch (InvalidOperationException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace MonoTests.System.Net.Http
|
||||
h.Dispose ();
|
||||
var c = new HttpClient (h);
|
||||
try {
|
||||
c.GetAsync ("http://google.com").Wait ();
|
||||
c.GetAsync ("http://www.example.com").Wait ();
|
||||
Assert.Fail ("#1");
|
||||
} catch (AggregateException e) {
|
||||
Assert.IsTrue (e.InnerException is ObjectDisposedException, "#2");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user