protected Exception GetException(Exception e) { e = HttpWebRequest.FlattenException(e); if (e is WebException) { return(e); } if (Operation.Aborted || e is OperationCanceledException || e is ObjectDisposedException) { return(HttpWebRequest.CreateRequestAbortedException()); } return(e); }
async Task <bool> CreateStream(WebOperation operation, bool reused, CancellationToken cancellationToken) { #if MONO_WEB_DEBUG var requestID = ++nextRequestID; #else var requestID = 0; #endif try { var stream = new NetworkStream(socket, false); Debug($"WC CREATE STREAM: Cnc={ID} {requestID} {reused} socket={socket.ID}"); if (operation.Request.Address.Scheme == Uri.UriSchemeHttps) { if (!reused || monoTlsStream == null) { if (ServicePoint.UseConnect) { if (tunnel == null) { tunnel = new WebConnectionTunnel(operation.Request, ServicePoint.Address); } await tunnel.Initialize(stream, cancellationToken).ConfigureAwait(false); if (!tunnel.Success) { return(false); } } monoTlsStream = new MonoTlsStream(operation.Request, stream); networkStream = await monoTlsStream.CreateStream(tunnel, cancellationToken).ConfigureAwait(false); } return(true); } networkStream = stream; return(true); } catch (Exception ex) { ex = HttpWebRequest.FlattenException(ex); Debug($"WC CREATE STREAM EX: Cnc={ID} {requestID} {operation.Aborted} - {ex.Message}"); if (operation.Aborted || monoTlsStream == null) { throw GetException(WebExceptionStatus.ConnectFailure, ex); } throw GetException(monoTlsStream.ExceptionStatus, ex); } finally { Debug($"WC CREATE STREAM DONE: Cnc={ID} {requestID}"); } }