Imported Upstream version 6.0.0.300

Former-commit-id: 5d008a9f41819eeae8c2feef3b41fc6cbf03e9fb
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-06-14 08:42:46 +00:00
parent a63e3f0156
commit 860af8198e
52 changed files with 68 additions and 39 deletions

View File

@@ -188,6 +188,12 @@ namespace System.Net.Http
public IDictionary<string, object> Properties => _delegatingHandler.Properties;
// Only used in MonoWebRequestHandler and ignored by the other handlers.
internal void SetWebRequestTimeout (TimeSpan timeout)
{
_delegatingHandler.SetWebRequestTimeout (timeout);
}
protected internal override Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) =>
_delegatingHandler.SendAsync (request, cancellationToken);
}

View File

@@ -78,5 +78,8 @@ namespace System.Net.Http
}
Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken);
// Only used by MonoWebRequestHandler and ignored by the other handlers.
void SetWebRequestTimeout (TimeSpan timeout);
}
}

View File

@@ -67,6 +67,7 @@ namespace System.Net.Http
bool unsafeAuthenticatedConnectionSharing;
bool sentRequest;
string connectionGroupName;
TimeSpan? timeout;
bool disposed;
internal MonoWebRequestHandler ()
@@ -368,6 +369,9 @@ namespace System.Net.Http
wr.ServicePoint.Expect100Continue = request.Headers.ExpectContinue == true;
if (timeout != null)
wr.Timeout = (int)timeout.Value.TotalMilliseconds;
// Add request headers
var headers = wr.Headers;
foreach (var header in request.Headers) {
@@ -533,5 +537,10 @@ namespace System.Net.Http
throw new NotImplementedException ();
}
}
void IMonoHttpClientHandler.SetWebRequestTimeout (TimeSpan timeout)
{
this.timeout = timeout;
}
}
}

View File

@@ -269,6 +269,9 @@ namespace System.Net.Http
async Task<HttpResponseMessage> SendAsyncWorker (HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
{
using (var lcts = CancellationTokenSource.CreateLinkedTokenSource (cts.Token, cancellationToken)) {
// Hack to pass the timeout to the HttpWebRequest that's created by MonoWebRequestHandler; all other handlers ignore this.
if (handler is HttpClientHandler clientHandler)
clientHandler.SetWebRequestTimeout (timeout);
lcts.CancelAfter (timeout);
var task = base.SendAsync (request, lcts.Token);

View File

@@ -169,5 +169,8 @@ namespace System.Net.Http
get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
}
// Only used in MonoWebRequestHandler and ignored by the other handlers.
internal void SetWebRequestTimeout (TimeSpan timeout) => throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
}
}

View File

@@ -33,7 +33,7 @@ namespace System.Net.Http
{
public class HttpMessageInvoker : IDisposable
{
HttpMessageHandler handler;
protected private HttpMessageHandler handler;
readonly bool disposeHandler;
public HttpMessageInvoker (HttpMessageHandler handler)

View File

@@ -40,6 +40,11 @@ namespace System.Net.Http
}
}
// This is only used by MonoWebRequestHandler.
void IMonoHttpClientHandler.SetWebRequestTimeout (TimeSpan timeout)
{
}
Task<HttpResponseMessage> IMonoHttpClientHandler.SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) => SendAsync (request, cancellationToken);
}
}