Esempio n. 1
0
        public static void Tune(HttpWebRequest request, TimeSpan timeout, WebRequestTransportSettings settings)
        {
            request.ConnectionGroupName = settings.ConnectionGroupName;
            request.Expect                              = null;
            request.KeepAlive                           = true;
            request.Pipelined                           = settings.Pipelined;
            request.Proxy                               = settings.Proxy;
            request.AllowAutoRedirect                   = settings.AllowAutoRedirect;
            request.AllowWriteStreamBuffering           = false;
            request.AllowReadStreamBuffering            = false;
            request.AuthenticationLevel                 = AuthenticationLevel.None;
            request.AutomaticDecompression              = DecompressionMethods.None;
            request.ServerCertificateValidationCallback = settings.RemoteCertificateValidationCallback;

            var servicePoint = request.ServicePoint;

            servicePoint.Expect100Continue = false;
            servicePoint.UseNagleAlgorithm = false;
            servicePoint.ConnectionLimit   = settings.MaxConnectionsPerEndpoint;
            servicePoint.MaxIdleTime       = (int)settings.ConnectionIdleTimeout.TotalMilliseconds;

            if (settings.TcpKeepAliveEnabled)
            {
                servicePoint.SetTcpKeepAlive(true, (int)settings.TcpKeepAliveTime.TotalMilliseconds, (int)settings.TcpKeepAliveInterval.TotalMilliseconds);
            }

            if (settings.ArpCacheWarmupEnabled)
            {
                if (servicePoint.BindIPEndPointDelegate == null)
                {
                    servicePoint.BindIPEndPointDelegate = AddressSniffer;
                }
            }
            else
            {
                servicePoint.BindIPEndPointDelegate = null;
            }

            if (!RuntimeDetector.IsMono)
            {
                servicePoint.ReceiveBufferSize = Constants.BufferSize;
            }

            var timeoutInMilliseconds = Math.Max(1, (int)timeout.TotalMilliseconds);

            request.Timeout          = timeoutInMilliseconds;
            request.ReadWriteTimeout = timeoutInMilliseconds;

            if (settings.ClientCertificates != null)
            {
                foreach (var certificate in settings.ClientCertificates)
                {
                    request.ClientCertificates.Add(certificate);
                }
            }
        }
        /// <inheritdoc cref="WebRequestTransport" />
        public WebRequestTransport(WebRequestTransportSettings settings, ILog log)
        {
            Settings = settings;

            this.log = log ?? throw new ArgumentNullException(nameof(log));

            connectTimeLimiter = new ConnectTimeLimiter(log);
            responseFactory    = new ResponseFactory(settings);

            WebRequestTuner.Touch();
        }
        public static HttpWebRequest Create(Request request, TimeSpan timeout, WebRequestTransportSettings settings, ILog log)
        {
            var webRequest = WebRequest.CreateHttp(request.Url);

            webRequest.Method = request.Method;

            WebRequestTuner.Tune(webRequest, timeout, settings);

            if (settings.FixNonAsciiHeaders)
            {
                request = NonAsciiHeadersFixer.Fix(request);
            }

            WebRequestHeadersFiller.Fill(request, webRequest, log);

            return(webRequest);
        }
Esempio n. 4
0
 public static void SetupWebRequestTransport(this IClusterClientConfiguration self, WebRequestTransportSettings settings)
 {
     self.Transport = new WebRequestTransport(settings, self.Log);
 }
 public ResponseFactory(WebRequestTransportSettings settings)
 {
     this.settings = settings;
 }