示例#1
0
        private void Redirect(Net.NetworkStream streamEnclosure)
        {
            StringBuilder sB = new StringBuilder();

            sB.AppendLine("HTTP/1.1 302 Object Moved");

            sB.AppendFormat("Date: {0}", DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", new CultureInfo("en-US")));
            sB.AppendLine();

            sB.AppendFormat("Location: {0}", this._RedirectedURL);
            sB.AppendLine();

            sB.AppendLine("Connection: close");

            this.Header.Cookie.AddOrUpdate(SessionCookieRequested?.Invoke(false));

            // put cookies because it may contain sessionid
            foreach (string key in this.Header.Cookie.Keys)
            {
                sB.AppendFormat("Set-Cookie: {0}", this.Header.Cookie[key].ToString());
                sB.AppendLine();
            }
            sB.AppendLine();

            byte[] buffer = Encoding.ASCII.GetBytes(sB.ToString());
            streamEnclosure.Write(buffer, 0, buffer.Length);
        }
示例#2
0
        private void PushHeaders(Stream streamEnclosure)
        {
            if (this._HeaderFlushed)
            {
                return;
            }

            this.Header.AddOrUpdate("Date", DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture));

            if (string.IsNullOrWhiteSpace(this.Header["Content-Type"]))
            {
                this.Header.AddOrUpdate("Content-Type", "text/html");
            }

            if (string.IsNullOrWhiteSpace(this.Header["Content-Length"]))
            {
                this.Header.AddOrUpdate("Content-Length", this._ResponseOutput.Length.ToString());
            }

            this.Header.AddOrUpdate("Connection", this._KeepAlive ? "keep-alive" : "close");
            if (this._KeepAlive)
            {
                this.Header.AddOrUpdate("Keep-Alive", $"timeout={streamEnclosure.ReadTimeout / 1000}");
            }

            this._ServerResponseStampHandler(this.Header);

            StringBuilder sB = new StringBuilder();

            sB.AppendFormat("HTTP/1.1 {0} {1}", this.Header.Status.Code, this.Header.Status.Message);
            sB.Append(Newline);

            foreach (string key in this.Header.Keys)
            {
                sB.AppendFormat("{0}: {1}", key, this.Header[key]);
                sB.Append(Newline);
            }

            string contentType =
                this.Header["Content-Type"];
            bool skip = string.IsNullOrEmpty(contentType) || contentType.IndexOf("text/html", StringComparison.Ordinal) == -1;

            this.Header.Cookie.AddOrUpdate(SessionCookieRequested?.Invoke(skip));

            foreach (string key in this.Header.Cookie.Keys)
            {
                sB.AppendFormat("Set-Cookie: {0}", this.Header.Cookie[key]);
                sB.Append(Newline);
            }

            sB.Append(Newline);

            byte[] buffer = Encoding.ASCII.GetBytes(sB.ToString());
            streamEnclosure.Write(buffer, 0, buffer.Length);

            this._HeaderFlushed = true;
        }
示例#3
0
        private void PushHeaders(Net.NetworkStream streamEnclosure)
        {
            this.Header.AddOrUpdate("Date", DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", new CultureInfo("en-US")));

            if (string.IsNullOrWhiteSpace(this.Header["Content-Type"]))
            {
                this.Header.AddOrUpdate("Content-Type", "text/html");
            }

            if (string.IsNullOrWhiteSpace(this.Header["Content-Length"]))
            {
                this.Header.AddOrUpdate("Content-Length", this._ResponseOutput.Length.ToString());
            }

            StringBuilder sB = new StringBuilder();

            sB.AppendFormat("HTTP/1.1 {0} {1}", this.Header.Status.Code, this.Header.Status.Message);
            sB.AppendLine();

            foreach (string key in this.Header.Keys)
            {
                sB.AppendFormat("{0}: {1}", key, this.Header[key]);
                sB.AppendLine();
            }

            string contentType =
                this.Header["Content-Type"];
            bool skip = (string.IsNullOrEmpty(contentType) || contentType.IndexOf("text/html") == -1);

            this.Header.Cookie.AddOrUpdate(SessionCookieRequested?.Invoke(skip));

            foreach (string key in this.Header.Cookie.Keys)
            {
                sB.AppendFormat("Set-Cookie: {0}", this.Header.Cookie[key].ToString());
                sB.AppendLine();
            }

            sB.AppendLine();

            byte[] buffer = Encoding.ASCII.GetBytes(sB.ToString());
            streamEnclosure.Write(buffer, 0, buffer.Length);
        }