Exemplo n.º 1
0
        internal void FinishInitialization()
        {
            if (_protocolVersion == HttpVersion.Version10)
            {
                finishInitialization10();
                return;
            }

            if (_userHostName == null)
            {
                _context.ErrorMessage = "Host header required";
                return;
            }

            var transferEnc = _headers["Transfer-Encoding"];

            if (transferEnc != null)
            {
                var comparison = StringComparison.OrdinalIgnoreCase;
                if (!transferEnc.Equals("chunked", comparison))
                {
                    _context.ErrorMessage = String.Empty;
                    _context.ErrorStatus  = 501;

                    return;
                }

                _chunked = true;
            }

            if (_httpMethod == "POST" || _httpMethod == "PUT")
            {
                if (_contentLength <= 0 && !_chunked)
                {
                    _context.ErrorMessage = String.Empty;
                    _context.ErrorStatus  = 411;

                    return;
                }
            }

            var expect = _headers["Expect"];

            if (expect != null)
            {
                var comparison = StringComparison.OrdinalIgnoreCase;
                if (!expect.Equals("100-continue", comparison))
                {
                    _context.ErrorMessage = "Invalid Expect header";
                    return;
                }

                var output = _connection.GetResponseStream();
                output.InternalWrite(_100continue, 0, _100continue.Length);
            }
        }
Exemplo n.º 2
0
        internal void FinishInitialization()
        {
            var host    = _headers["Host"];
            var hasHost = host != null && host.Length > 0;

            if (_protocolVersion > HttpVersion.Version10 && !hasHost)
            {
                _context.ErrorMessage = "Invalid Host header";
                return;
            }

            _url = HttpUtility.CreateRequestUrl(
                _uri,
                hasHost ? host : UserHostAddress,
                IsWebSocketRequest,
                IsSecureConnection
                );

            if (_url == null)
            {
                _context.ErrorMessage = "Invalid request url";
                return;
            }

            var transferEnc = _headers["Transfer-Encoding"];

            if (transferEnc != null)
            {
                if (_protocolVersion < HttpVersion.Version11)
                {
                    _context.ErrorMessage = "Invalid Transfer-Encoding header";
                    return;
                }

                var comparison = StringComparison.OrdinalIgnoreCase;
                if (!transferEnc.Equals("chunked", comparison))
                {
                    _context.ErrorMessage = String.Empty;
                    _context.ErrorStatus  = 501;

                    return;
                }

                _chunked = true;
            }

            if (_contentLength == -1 && !_chunked)
            {
                if (_httpMethod == "POST" || _httpMethod == "PUT")
                {
                    _context.ErrorMessage = String.Empty;
                    _context.ErrorStatus  = 411;

                    return;
                }
            }

            var expect = _headers["Expect"];

            if (_protocolVersion > HttpVersion.Version10 && expect != null)
            {
                var comparison = StringComparison.OrdinalIgnoreCase;
                if (!expect.Equals("100-continue", comparison))
                {
                    _context.ErrorMessage = "Invalid Expect header";
                    return;
                }

                var output = _connection.GetResponseStream();
                output.InternalWrite(_100continue, 0, _100continue.Length);
            }
        }