public async Task <HttpRequestMessage> BuildHttpRequestMessage(HttpHandlerOptions httpHandlerOptions, HttpMethod httpMethod, object content) { var requestUri = String.IsNullOrWhiteSpace(Path) ? httpHandlerOptions.RequestUri : new Uri(httpHandlerOptions.RequestUri, Path); if (QueryParameters.Any()) { var qb = new QueryBuilder(); if (!String.IsNullOrWhiteSpace(requestUri.Query)) { var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(requestUri.Query); foreach (var(key, value) in query) { qb.Add(key, value.ToArray()); } } foreach (var(key, value) in QueryParameters) { qb.Add(key, value.ToArray()); } var uriBuilder = new UriBuilder(requestUri); uriBuilder.Query = qb.ToQueryString().ToString(); requestUri = uriBuilder.Uri; } var message = new HttpRequestMessage(httpMethod, requestUri); if (content != null) { message.Content = await CreateHttpContent(content); } if (!String.IsNullOrWhiteSpace(ContentType)) { message.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType); } return(message); }
private static HttpMessageHandler ValueFactory(HttpHandlerOptions handlerOptions) { var socketsHandler = new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromSeconds(60), PooledConnectionIdleTimeout = TimeSpan.FromMinutes(20), MaxConnectionsPerServer = 2 }; if (handlerOptions.Proxy != null) { socketsHandler.Proxy = handlerOptions.Proxy; } if (handlerOptions.IgnoreProxy) { socketsHandler.UseProxy = false; } return(socketsHandler); }
public ReadonlyHttpHandlerOptions(HttpHandlerOptions httpHandlerOptions) { DestinationHost = httpHandlerOptions.RequestUri?.Host; ProxyHost = httpHandlerOptions.Proxy?.Address?.Host; IgnoreProxy = httpHandlerOptions.IgnoreProxy; }
public HttpOptionsBuilder(string url) { _httpHandlerOptions = new HttpHandlerOptions(UriHelper.BuildUri(url)); }
public HttpRequestBuilder Client(string url, HttpHandlerOptions options) { return(new HttpRequestBuilder(options)); }
public HttpRequestBuilder(HttpHandlerOptions httpHandlerOptions) { _httpHandlerOptions = httpHandlerOptions; }
public static HttpMessageHandler Build(HttpHandlerOptions handlerOptions) { var roHttpHandlerOptions = new ReadonlyHttpHandlerOptions(handlerOptions); return(HttpHandlers.GetOrAdd(roHttpHandlerOptions, _ => ValueFactory(handlerOptions))); }