Beispiel #1
0
        public void Redirect()
        {
            string mainStr = "HTTP/" + VersionString() + " " + (int)StatusCode.SEE_OTHER + " " + SonicHTTPStatus.StatusToString(StatusCode.SEE_OTHER) + "\r\n";

            mainStr += "Location:" + RedirectLocation + "\r\n\r\n";
            byte[] buffer = ToBytes(mainStr);
            IsRedirectionRequest = true;
            OutputStream.Write(buffer, 0, buffer.Length);
            OutputStream.Flush();
            OutputStream.Close();
            IsRedirectionRequest = false;
        }
Beispiel #2
0
        private string HeaderBuilder()
        {
            StringBuilder builder = new StringBuilder("HTTP/" + VersionString());

            builder.Append(" " + ((int)StatusCode) + " ");
            if (StatusDescription == null)
            {
                builder.Append(SonicHTTPStatus.StatusToString(StatusCode) + EOL);
            }
            else
            {
                builder.Append(StatusDescription + EOL);
            }


            if (ContentLength64 != 0)
            {
                builder.Append("Content-Length:" + ContentLength64.ToString() + EOL);
            }

            if (ContentType != MIMEType.NONE)
            {
                builder.Append("Content-Type:" + SonicMIMEType.MIMEToString(ContentType) + EOL);
            }

            if (KeepAlive)
            {
                builder.Append("Connection:keep-alive" + EOL);
            }
            else
            {
                builder.Append("Connection:close" + EOL);
            }

            if (ContentEncoding != null)
            {
                builder.Append("Content-Encoding:" + ContentEncoding + EOL);
            }

            if (AcceptRanges != null)
            {
                builder.Append("Accept-Ranges:" + AcceptRanges + EOL);
            }

            if (ContentRange != null)
            {
                builder.Append("Content-Range:" + ContentRange + EOL);
            }

            if (SendChunked)
            {
                builder.Append("Transfer-Encoding:chunked" + EOL);
            }

            foreach (string value in HeaderList)
            {
                builder.Append(value + EOL);
            }
            foreach (string c in Cookies)
            {
                builder.Append(c + EOL);
            }
            builder.Append(EOL);
            return(builder.ToString());
        }