예제 #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);
        }
예제 #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);
        }
예제 #3
0
 public ReadonlyHttpHandlerOptions(HttpHandlerOptions httpHandlerOptions)
 {
     DestinationHost = httpHandlerOptions.RequestUri?.Host;
     ProxyHost       = httpHandlerOptions.Proxy?.Address?.Host;
     IgnoreProxy     = httpHandlerOptions.IgnoreProxy;
 }
예제 #4
0
 public HttpOptionsBuilder(string url)
 {
     _httpHandlerOptions = new HttpHandlerOptions(UriHelper.BuildUri(url));
 }
예제 #5
0
파일: Http.cs 프로젝트: ToanDao2612/middler
 public HttpRequestBuilder Client(string url, HttpHandlerOptions options)
 {
     return(new HttpRequestBuilder(options));
 }
예제 #6
0
 public HttpRequestBuilder(HttpHandlerOptions httpHandlerOptions)
 {
     _httpHandlerOptions = httpHandlerOptions;
 }
예제 #7
0
        public static HttpMessageHandler Build(HttpHandlerOptions handlerOptions)
        {
            var roHttpHandlerOptions = new ReadonlyHttpHandlerOptions(handlerOptions);

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