Ejemplo n.º 1
0
        /// <summary>Sets up status code and contentLength from the headers.
        /// Returns true if we're redirecting.</summary>
        private bool LoadStatusAndLength()
        {
            // Pull the status code:
            string statusLine = responseHeaders.status;

            if (statusLine != null)
            {
                int statusCodeStart = statusLine.IndexOf(' ') + 1;
                int statusCodeEnd   = statusLine.IndexOf(' ', statusCodeStart);

                // Pull the code:
                string code = statusLine.Substring(statusCodeStart, statusCodeEnd - statusCodeStart);

                if (!int.TryParse(code, out statusCode))
                {
                    // Assume 200:
                    statusCode = 200;
                }
            }

            // Get the content length:
            string cLength = responseHeaders["content-length"];

            if (cLength != null)
            {
                int.TryParse(cLength, out contentLength);
            }

            // Did it try to set any cookies? Handle those:
            Cookies.Handle(this);

            // Remote timeout?
            if (statusCode == 408)
            {
                TimedOut();
                return(false);
            }

            // Redirect?
            return((statusCode >= 300 && statusCode < 400) && statusCode != 304);
        }