case HttpConnectionKind.SocksTunnel:
case HttpConnectionKind.SslSocksTunnel:
- Debug.Assert(_originAuthority != null);
- Debug.Assert(_proxyUri != null);
- (socket, stream) = await ConnectToTcpHostAsync(_proxyUri.IdnHost, _proxyUri.Port, request, async, cancellationToken).ConfigureAwait(false);
- await SocksHelper.EstablishSocksTunnelAsync(stream, _originAuthority.IdnHost, _originAuthority.Port, _proxyUri, ProxyCredentials, async, cancellationToken).ConfigureAwait(false);
+ (socket, stream) = await EstablishSocksTunnel(request, async, cancellationToken).ConfigureAwait(false);
break;
}
}
}
+ private async ValueTask<(Socket? socket, Stream stream)> EstablishSocksTunnel(HttpRequestMessage request, bool async, CancellationToken cancellationToken)
+ {
+ Debug.Assert(_originAuthority != null);
+ Debug.Assert(_proxyUri != null);
+
+ (Socket? socket, Stream stream) = await ConnectToTcpHostAsync(_proxyUri.IdnHost, _proxyUri.Port, request, async, cancellationToken).ConfigureAwait(false);
+
+ try
+ {
+ await SocksHelper.EstablishSocksTunnelAsync(stream, _originAuthority.IdnHost, _originAuthority.Port, _proxyUri, ProxyCredentials, async, cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception e) when (!(e is OperationCanceledException))
+ {
+ Debug.Assert(!(e is HttpRequestException));
+ throw new HttpRequestException(SR.net_http_request_aborted, e);
+ }
+
+ return (socket, stream);
+ }
+
/// <summary>Enqueues a waiter to the waiters list.</summary>
private TaskCompletionSourceWithCancellation<HttpConnection?> EnqueueWaiter()
{
HttpRequestMessage request = CreateRequest(HttpMethod.Get, new Uri($"http://{host}/"), UseVersion, exactVersion: true);
// SocksException is not public
- var ex = await Assert.ThrowsAnyAsync<IOException>(() => client.SendAsync(TestAsync, request));
- Assert.Equal(exceptionMessage, ex.Message);
- Assert.Equal("SocksException", ex.GetType().Name);
+ var ex = await Assert.ThrowsAnyAsync<HttpRequestException>(() => client.SendAsync(TestAsync, request));
+ var innerException = ex.InnerException;
+ Assert.Equal(exceptionMessage, innerException.Message);
+ Assert.Equal("SocksException", innerException.GetType().Name);
}
}