Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public ReadonlyHttpHandlerOptions(HttpHandlerOptions httpHandlerOptions)
 {
     DestinationHost = httpHandlerOptions.RequestUri?.Host;
     ProxyHost       = httpHandlerOptions.Proxy?.Address?.Host;
     IgnoreProxy     = httpHandlerOptions.IgnoreProxy;
 }
Esempio n. 4
0
 public HttpOptionsBuilder(string url)
 {
     _httpHandlerOptions = new HttpHandlerOptions(UriHelper.BuildUri(url));
 }
Esempio n. 5
0
 public HttpRequestBuilder Client(string url, HttpHandlerOptions options)
 {
     return(new HttpRequestBuilder(options));
 }
Esempio n. 6
0
 public HttpRequestBuilder(HttpHandlerOptions httpHandlerOptions)
 {
     _httpHandlerOptions = httpHandlerOptions;
 }
Esempio n. 7
0
        public static HttpMessageHandler Build(HttpHandlerOptions handlerOptions)
        {
            var roHttpHandlerOptions = new ReadonlyHttpHandlerOptions(handlerOptions);

            return(HttpHandlers.GetOrAdd(roHttpHandlerOptions, _ => ValueFactory(handlerOptions)));
        }