Пример #1
0
 private ViewContentType GetViewContentType()
 {
     if ((Headers != null) && Headers.Exists("Content-Type"))
     {
         try
         {
             string contentType = Headers["Content-Type"].ToLower();
             if (contentType.Contains("json"))
             {
                 return(ViewContentType.Json);
             }
         }
         catch
         {
         }
     }
     return(ViewContentType.Xml);
 }
Пример #2
0
 public bool HeaderExists(string name, string value)
 {
     return(Headers.Exists(name, value));
 }
Пример #3
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);
        }
Пример #4
0
        internal bool ReadRequest()
        {
            if (_requestData == null || ClientSocket == null)
            {
                return(false);
            }

            int  readCount     = 0;
            bool flagReadError = false;
            bool flag2         = false;
            var  data          = new byte[0x2000];

            do
            {
                try
                {
                    readCount = ClientSocket.Receive(data);
                }
                catch (Exception)
                {
                    flagReadError = true;
                }

                if (readCount <= 0)
                {
                    flag2 = true;
                }
                else
                {
                    if (_requestData.Length == 0L)
                    {
                        int index = 0;
                        while ((index < readCount) && ((data[index] == 13) || (data[index] == 10)))
                        {
                            index++;
                        }

                        _requestData.Write(data, index, readCount - index);
                    }
                    else
                    {
                        _requestData.Write(data, 0, readCount);
                    }
                }
            }while ((!flag2 && !flagReadError) && !IsRequestComplete());

            data = null;
            if (flagReadError)
            {
                return(false);
            }

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

            if (_hostFromURI != null)
            {
                if (Headers.Exists("Host") && !Utilities.AreOriginsEquivalent(_hostFromURI, Headers["Host"], 80))
                {
                    Headers["Host"] = _hostFromURI;
                }
                else if (!Headers.Exists("Host"))
                {
                    Headers["Host"] = _hostFromURI;
                }
            }

            return(Headers.Exists("Host"));
        }