Esempio n. 1
0
        private ClusterConfig GetClusterConfig(string id, ActiveHealthCheckOptions healthCheckOptions, Version version
#if NET
                                               , HttpVersionPolicy versionPolicy = HttpVersionPolicy.RequestVersionExact
#endif
                                               )
        {
            return(new ClusterConfig(
                       new Cluster
            {
                Id = id,
                HealthCheck = new HealthCheckOptions()
                {
                    Active = healthCheckOptions,
                },
                HttpRequest = new RequestProxyOptions
                {
                    Timeout = TimeSpan.FromSeconds(60),
                    Version = version,
#if NET
                    VersionPolicy = versionPolicy,
#endif
                }
            },
                       null));
        }
 /// <summary>
 /// Instantiates a new <see cref="HttpTunnelConnectionFactory"/>.
 /// </summary>
 /// <param name="httpConnection">The <see cref="HttpConnection"/> to open a tunnel over.</param>
 /// <param name="httpVersion">The HTTP version to establish the connect tunnel over.</param>
 /// <param name="httpVersionPolicy">A policy controlling what HTTP version will be used for the connect tunnel.</param>
 /// <param name="ownsConnection">If true, the <paramref name="httpConnection"/> will be disposed when the <see cref=" HttpTunnelConnectionFactory"/> tunnel is disposed.</param>
 public HttpTunnelConnectionFactory(HttpConnection httpConnection, HttpPrimitiveVersion httpVersion, HttpVersionPolicy httpVersionPolicy, bool ownsConnection = false)
 {
     _httpConnection    = httpConnection ?? throw new ArgumentNullException(nameof(httpConnection));
     _httpVersion       = httpVersion ?? throw new ArgumentNullException(nameof(httpVersion));
     _httpVersionPolicy = httpVersionPolicy;
     _ownsConnection    = ownsConnection;
 }
        private ClusterModel GetClusterConfig(string id, ActiveHealthCheckConfig healthCheckOptions, Version version
#if NET
                                              , HttpVersionPolicy versionPolicy = HttpVersionPolicy.RequestVersionExact
#endif
                                              )
        {
            return(new ClusterModel(
                       new ClusterConfig
            {
                ClusterId = id,
                HealthCheck = new HealthCheckConfig()
                {
                    Active = healthCheckOptions,
                },
                HttpRequest = new ForwarderRequestConfig
                {
                    Timeout = TimeSpan.FromSeconds(60),
                    Version = version,
#if NET
                    VersionPolicy = versionPolicy,
#endif
                }
            },
                       new HttpMessageInvoker(new HttpClientHandler())));
        }
Esempio n. 4
0
 public static string GetVersionPolicy(HttpVersionPolicy policy)
 {
     return(policy switch
     {
         HttpVersionPolicy.RequestVersionOrLower => "RequestVersionOrLower",
         HttpVersionPolicy.RequestVersionOrHigher => "RequestVersionOrHigher",
         HttpVersionPolicy.RequestVersionExact => "RequestVersionExact",
         _ => throw new NotImplementedException(policy.ToString()),
     });
Esempio n. 5
0
 public HttpRequestMessage(HttpMethod method, Uri?requestUri)
 {
     // It's OK to have a 'null' request Uri. If HttpClient is used, the 'BaseAddress' will be added.
     // If there is no 'BaseAddress', sending this request message will throw.
     // Note that we also allow the string to be empty: null and empty are considered equivalent.
     _method        = method ?? throw new ArgumentNullException(nameof(method));
     _requestUri    = requestUri;
     _version       = DefaultRequestVersion;
     _versionPolicy = DefaultVersionPolicy;
 }
        private ClusterConfig GetClusterConfig(string id, ClusterActiveHealthCheckOptions healthCheckOptions, Version version
#if NET
                                               , HttpVersionPolicy versionPolicy = HttpVersionPolicy.RequestVersionExact
#endif
                                               )
        {
            return(new ClusterConfig(
                       new Cluster {
                Id = id
            },
                       new ClusterHealthCheckOptions(default, healthCheckOptions),
Esempio n. 7
0
        private void InitializeValues(HttpMethod method, Uri?requestUri)
        {
            if (method is null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if ((requestUri != null) && (requestUri.IsAbsoluteUri) && (!HttpUtilities.IsHttpUri(requestUri)))
            {
                throw new ArgumentException(SR.net_http_client_http_baseaddress_required, nameof(requestUri));
            }

            _method        = method;
            _requestUri    = requestUri;
            _version       = HttpUtilities.DefaultRequestVersion;
            _versionPolicy = HttpUtilities.DefaultVersionPolicy;
        }
Esempio n. 8
0
 private void RequestStart(string scheme, string host, int port, string pathAndQuery, byte versionMajor, byte versionMinor, HttpVersionPolicy versionPolicy)
 {
     Interlocked.Increment(ref _startedRequests);
     WriteEvent(eventId: 1, scheme, host, port, pathAndQuery, versionMajor, versionMinor, versionPolicy);
 }
Esempio n. 9
0
        private unsafe void WriteEvent(int eventId, string?arg1, string?arg2, int arg3, string?arg4, byte arg5, byte arg6, HttpVersionPolicy arg7)
        {
            arg1 ??= "";
            arg2 ??= "";
            arg4 ??= "";

            fixed(char *arg1Ptr = arg1)
            fixed(char *arg2Ptr = arg2)
            fixed(char *arg4Ptr = arg4)
            {
                const int  NumEventDatas = 7;
                EventData *descrs        = stackalloc EventData[NumEventDatas];

                descrs[0] = new EventData
                {
                    DataPointer = (IntPtr)(arg1Ptr),
                    Size        = (arg1.Length + 1) * sizeof(char)
                };
                descrs[1] = new EventData
                {
                    DataPointer = (IntPtr)(arg2Ptr),
                    Size        = (arg2.Length + 1) * sizeof(char)
                };
                descrs[2] = new EventData
                {
                    DataPointer = (IntPtr)(&arg3),
                    Size        = sizeof(int)
                };
                descrs[3] = new EventData
                {
                    DataPointer = (IntPtr)(arg4Ptr),
                    Size        = (arg4.Length + 1) * sizeof(char)
                };
                descrs[4] = new EventData
                {
                    DataPointer = (IntPtr)(&arg5),
                    Size        = sizeof(byte)
                };
                descrs[5] = new EventData
                {
                    DataPointer = (IntPtr)(&arg6),
                    Size        = sizeof(byte)
                };
                descrs[6] = new EventData
                {
                    DataPointer = (IntPtr)(&arg7),
                    Size        = sizeof(HttpVersionPolicy)
                };

                WriteEventCore(eventId, NumEventDatas, descrs);
            }
        }
Esempio n. 10
0
        /// <inheritdoc/>
        public override ValueTask <ValueHttpRequest?> CreateNewRequestAsync(HttpPrimitiveVersion version, HttpVersionPolicy versionPolicy, CancellationToken cancellationToken = default)
        {
            if (_writeBuffer.ActiveLength != 0 || _responseContentBytesRemaining != 0)
            {
                return(ValueTask.FromException <ValueHttpRequest?>(ExceptionDispatchInfo.SetCurrentStackTrace(new Exception("Unable to create request stream with a request already pending."))));
            }

            if (version.Major != 1)
            {
                if (versionPolicy == HttpVersionPolicy.RequestVersionOrLower)
                {
                    version = HttpPrimitiveVersion.Version11;
                }
                return(ValueTask.FromException <ValueHttpRequest?>(ExceptionDispatchInfo.SetCurrentStackTrace(new Exception($"Unable to create request for HTTP/{version.Major}.{version.Minor} with a {nameof(Http1Connection)}."))));
            }

            _writeState                = WriteState.Unstarted;
            _requestIsChunked          = true;
            _responseHasContentLength  = false;
            _responseIsChunked         = false;
            _readingFirstResponseChunk = false;
            _readFunc = s_ReadResponse;

            if (Interlocked.Exchange(ref _request, null) is Http1Request request)
            {
                request.Init(this, version);
            }
            else
            {
                request = new Http1Request(this, version);
            }

            return(new ValueTask <ValueHttpRequest?>(request.GetValueRequest()));
        }
Esempio n. 11
0
 /// <summary>
 /// Opens a new request on the connection.
 /// </summary>
 /// <param name="version">The HTTP version of the request to make.</param>
 /// <param name="versionPolicy">A policy controlling version selection for the request.</param>
 /// <param name="cancellationToken">A cancellation token for this operation.</param>
 /// <returns>
 /// If a request can be made, a <see cref="HttpRequest"/> instance used to make a single request.
 /// Otherwise, null to indicate the connection is not accepting new requests.
 /// </returns>
 /// <remarks>
 /// This should return null if the connection has been gracefully closed e.g. connection reset, received GOAWAY, etc.
 /// </remarks>
 public abstract ValueTask <ValueHttpRequest?> CreateNewRequestAsync(HttpPrimitiveVersion version, HttpVersionPolicy versionPolicy, CancellationToken cancellationToken = default);
Esempio n. 12
0
        public void OnRequestStart(DateTime timestamp, string scheme, string host, int port, string pathAndQuery, int versionMajor, int versionMinor, HttpVersionPolicy versionPolicy)
        {
            var metrics = PerRequestMetrics.Current;

            metrics.HttpRequestStartOffset = metrics.CalcOffset(timestamp);
        }
 public void OnRequestStart(DateTime timestamp, string scheme, string host, int port, string pathAndQuery, int versionMajor, int versionMinor, HttpVersionPolicy versionPolicy) => AddStage(nameof(OnRequestStart), timestamp);