Beispiel #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);
        }
Beispiel #2
0
        public void Write(byte[] buffer, int offset, int count)
        {
            if (this._HeaderFlushed)
            {
                Net.NetworkStream streamEnclosure = null;
                StreamEnclosureRequested?.Invoke(out streamEnclosure);

                if (streamEnclosure == null)
                {
                    throw new Exception("Inaccessible stream enclosure to do realtime streaming on http response socket!");
                }

                streamEnclosure.Write(buffer, offset, count);

                return;
            }

            this._ResponseOutput.Write(buffer, offset, count);
        }
Beispiel #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);
        }