예제 #1
0
 private void SendHeaders(bool eos)
 {
     m_Output.SendHeaders(Headers, (uint)StatusCode, eos);
     m_IsHeaderSent = true;
 }
예제 #2
0
        private static Stream DoStreamRequestHttp2(
            Request request,
            Uri uri,
            Http2Connection.Http2Stream reuseStream = null)
        {
            bool   doPost = false;
            string encval;

redoafter401:
            var actheaders = new Dictionary <string, string>();

            actheaders.Add(":method", request.Method);
            actheaders.Add(":scheme", uri.Scheme);
            actheaders.Add(":path", uri.PathAndQuery);
            if (uri.IsDefaultPort)
            {
                actheaders.Add(":authority", uri.Host);
            }
            else
            {
                actheaders.Add(":authority", $"{uri.Host}:{uri.Port}");
            }

            IDictionary <string, string> headers = request.Headers;
            string content_type      = request.RequestContentType;
            bool   compressed        = request.IsCompressed;
            bool   expect100Continue = request.Expect100Continue;

            if (headers != null)
            {
                foreach (KeyValuePair <string, string> k in headers)
                {
                    string kn = k.Key.ToLower();
                    if (kn == "content-length" ||
                        kn == "content-type" ||
                        kn == "connection" ||
                        kn == "expect")
                    {
                        continue;
                    }
                    actheaders.Add(kn, k.Value);
                }
            }

            if (request.Authorization != null)
            {
                request.Authorization.GetRequestHeaders(actheaders, request.Method, uri.PathAndQuery);
            }

            if (actheaders.TryGetValue("transfer-encoding", out encval) && encval == "chunked")
            {
                actheaders.Remove("transfer-encoding");
            }

            if (request.RequestBodyDelegate != null)
            {
                doPost = true;
                if (content_type != null)
                {
                    actheaders.Add("content-type", content_type);
                }
                if (compressed && content_type != "application/x-gzip")
                {
                    actheaders.Add("x-content-encoding", "gzip");
                }

                if (expect100Continue)
                {
                    actheaders.Add("expect", "100-continue");
                }
            }

            if (request.Method != "HEAD")
            {
                actheaders.Add("Accept-Encoding", "gzip, deflate");
            }

            int retrycnt = 1;

retry:
            Http2Connection.Http2Stream s = reuseStream ?? OpenHttp2Stream(uri.Scheme, uri.Host, uri.Port, request.ClientCertificates, request.EnabledSslProtocols, request.CheckCertificateRevocation, request.RemoteCertificateValidationCallback, request.EnableIPv6 && OSSupportsIPv6);
            headers.Clear();
            try
            {
                s.SendHeaders(actheaders, 0, !doPost);
            }
            catch (ObjectDisposedException)
            {
                if (retrycnt-- > 0)
                {
                    goto retry;
                }
                throw;
            }
            catch (SocketException)
            {
                if (retrycnt-- > 0)
                {
                    goto retry;
                }
                throw;
            }
            catch (IOException)
            {
                if (retrycnt-- > 0)
                {
                    goto retry;
                }
                throw;
            }
            s.ReadTimeout = 10000;

            try
            {
                return(DoStreamRequestHttp2Response(
                           s,
                           request,
                           uri,
                           doPost));
            }
            catch (RedoAfter401Exception)
            {
                goto redoafter401;
            }
        }