Exemplo n.º 1
0
        private bool IsRequestComplete()
        {
            if (Headers == null)
            {
                if (!HeadersAvailable())
                {
                    return(false);
                }

                if (!ParseRequestForHeaders())
                {
                    if (Headers == null)
                    {
                        Headers = new HttpRequestHeaders {
                            HttpMethod = "BAD"
                        };
                        Headers["Host"]     = "BAD-REQUEST";
                        Headers.RequestPath = "/BAD_REQUEST";
                    }

                    FailSession(400, "Bad Request", "Request Header parsing failed.");
                    return(true);
                }
            }

            if (Headers == null)
            {
                return(false);
            }

            if (Headers.ExistsAndEquals("Transfer-encoding", "chunked"))
            {
                return(Utilities.IsChunkedBodyComplete(_requestData, _intEntityBodyOffset));
            }

            if (Headers.Exists("Content-Length"))
            {
                try
                {
                    long result;
                    if (!long.TryParse(Headers["Content-Length"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result) || (result < 0L))
                    {
                        FailSession(400, "Bad Request", "Request Content-Length header parsing failed.");
                        return(true);
                    }

                    if ((result == 0L) && ("GET" != Headers.HttpMethod))
                    {
                        FailSession(400, "Bad Request", "This HTTP method requires a request body.");
                    }

                    return(_requestData.Length >= (_intEntityBodyOffset + result));
                }
                catch
                {
                    FailSession(400, "Bad Request", "Unknown error: Check content length header.");
                    return(false);
                }
            }

            if ("GET" != Headers.HttpMethod)
            {
                FailSession(0x19b, "Bad Request", "This HTTP method requires a request body.");
            }

            return(true);
        }