public async Task <HttpConnectResponse> SendAsync(HttpConnectRequest request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } cancellationToken.ThrowIfCancellationRequested(); PrepareRequest(request); HttpConnectContext context = new HttpConnectContext(request, cancellationToken); try { await _pipeline.Invoke(context).ConfigureAwait(false); return(context.Response); } catch (Exception ex) { // if no response value the create one if (context.Response == null) { context.Response = new HttpConnectResponse(); } context.Response.SetError(ex); } return(context.Response); }
private void PrepareRequest(HttpConnectRequest request) { if (_baseUri == null && !request.RequestUri.IsAbsoluteUri) { throw new InvalidOperationException("An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set."); } if (!request.RequestUri.IsAbsoluteUri) { request.RequestUri = new Uri(_baseUri, request.RequestUri); } }
public async Task <HttpConnectResponse <T> > SendAsync <T>(HttpConnectRequest request, CancellationToken cancellationToken) { HttpConnectResponse response = await SendAsync(request, cancellationToken); try { if (response.IsSuccess) { var deserializedResponse = new HttpConnectResponse <T>(response); deserializedResponse.Data = deserializedResponse.Content.Deserialize <T>(); return(deserializedResponse); } return(new HttpConnectResponse <T>(response)); } catch (Exception exception) { HttpConnectResponse <T> errorResponse = new HttpConnectResponse <T>(response); errorResponse.SetError(exception); return(errorResponse); } }
public HttpConnectContext(HttpConnectRequest request, CancellationToken requestAborted = default) { Request = request ?? throw new System.ArgumentNullException(nameof(request)); RequestAborted = requestAborted; }