Example #1
0
        public override FileBlock CreateFileBlock()
        {
            FileBlock result = base.CreateFileBlock();

            result.GZip = this.GZIP;
            return(result);
        }
Example #2
0
        private void OnEncode(ISession session, object data, System.IO.Stream stream)
        {
            PipeStream pstream = stream.ToPipeStream();

            StaticResurce.FileBlock fb = data as StaticResurce.FileBlock;
            if (fb != null)
            {
                fb.Write(pstream);
            }
            else
            {
                HttpResponse response = (HttpResponse)data;
                response.Write(pstream);
            }
        }
Example #3
0
        internal void Write(PipeStream stream)
        {
            stream.Write(HttpVersion);
            stream.Write(HeaderType.SPACE_BYTES[0]);
            stream.Write(mCode);
            stream.Write(HeaderType.SPACE_BYTES[0]);
            stream.Write(CodeMsg);
            stream.Write(HeaderType.LINE_BYTES);
            Header.Write(stream);
            for (int i = 0; i < mSetCookies.Count; i++)
            {
                HeaderType.Write(HeaderType.SET_COOKIE, stream);
                stream.Write(mSetCookies[i]);
                stream.Write(HeaderType.LINE_BYTES);
            }
            if (mBody != null)
            {
                StaticResurce.FileBlock fb = mBody as StaticResurce.FileBlock;
                if (fb != null)
                {
                    stream.Write(HeaderType.LINE_BYTES);
                    fb.Write(stream);
                }
                else
                {
                    MemoryBlockCollection contentLength = stream.Allocate(28);
                    stream.Write(HeaderType.LINE_BYTES);
                    int count = Serializer.Serialize(stream, mBody);
                    contentLength.Full("Content-Length: " + count.ToString().PadRight(10) + "\r\n", stream.Encoding);
                }
            }
            else
            {
                stream.Write(HeaderType.NULL_CONTENT_LENGTH_BYTES);
                stream.Write(HeaderType.LINE_BYTES);
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Debug))
            {
                Session.Server.Log(EventArgs.LogType.Debug, Session, "{0} {1}", Request.ClientIPAddress, this.ToString());
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Info))
            {
                Session.Server.Log(EventArgs.LogType.Info, Session, "{4} {0} {1} response {2} {3}", Request.Method, Request.Url, Code, CodeMsg, Request.ClientIPAddress);
            }
        }
Example #4
0
 internal void Write(PipeStream stream)
 {
     stream.Write(HttpVersion);
     stream.Write(HeaderType.SPACE_BYTES[0]);
     stream.Write(mCode);
     stream.Write(HeaderType.SPACE_BYTES[0]);
     stream.Write(CodeMsg);
     stream.Write(HeaderType.LINE_BYTES);
     Header.Write(stream);
     for (int i = 0; i < mSetCookies.Count; i++)
     {
         HeaderType.Write(HeaderType.SET_COOKIE, stream);
         stream.Write(mSetCookies[i]);
         stream.Write(HeaderType.LINE_BYTES);
     }
     if (mBody != null)
     {
         StaticResurce.FileBlock fb = mBody as StaticResurce.FileBlock;
         if (fb != null)
         {
             stream.Write(HeaderType.LINE_BYTES);
             fb.Write(stream);
         }
         else
         {
             MemoryBlockCollection contentLength = stream.Allocate(28);
             stream.Write(HeaderType.LINE_BYTES);
             int count = Serializer.Serialize(stream, mBody);
             contentLength.Full("Content-Length: " + count.ToString().PadRight(10) + "\r\n", stream.Encoding);
         }
     }
     else
     {
         stream.Write(HeaderType.NULL_CONTENT_LENGTH_BYTES);
         stream.Write(HeaderType.LINE_BYTES);
     }
 }
Example #5
0
        private void OnWrite(PipeStream stream)
        {
            IResult result = mBody as IResult;

            if (result != null)
            {
                this.Header[HeaderTypeFactory.CONTENT_TYPE] = result.ContentType;
                result.Setting(this);
            }

            byte[] buffer = HttpParse.GetByteBuffer();

            int hlen = 0;

            hlen         = hlen + Encoding.ASCII.GetBytes(HttpVersion, 0, HttpVersion.Length, buffer, hlen);
            buffer[hlen] = HeaderTypeFactory._SPACE_BYTE;
            hlen++;
            hlen         = hlen + Encoding.ASCII.GetBytes(Code, 0, Code.Length, buffer, hlen);
            buffer[hlen] = HeaderTypeFactory._SPACE_BYTE;
            hlen++;
            hlen = hlen + Encoding.ASCII.GetBytes(CodeMsg, 0, CodeMsg.Length, buffer, hlen);

            buffer[hlen] = HeaderTypeFactory._LINE_R;
            hlen++;
            buffer[hlen] = HeaderTypeFactory._LINE_N;
            hlen++;

            stream.Write(buffer, 0, hlen);
            stream.Write(HeaderTypeFactory.SERVAR_HEADER_BYTES, 0, HeaderTypeFactory.SERVAR_HEADER_BYTES.Length);
            Header.Write(stream);
            for (int i = 0; i < mSetCookies.Count; i++)
            {
                HeaderTypeFactory.Write(HeaderTypeFactory.SET_COOKIE, stream);
                stream.Write(mSetCookies[i]);
                stream.Write(HeaderTypeFactory.LINE_BYTES, 0, 2);
            }
            if (mBody != null)
            {
                StaticResurce.FileBlock fb = mBody as StaticResurce.FileBlock;
                if (fb != null)
                {
                    stream.Write(HeaderTypeFactory.LINE_BYTES, 0, 2);
                    fb.Write(stream);
                }
                else
                {
                    if (result.HasBody)
                    {
                        if (result.Length > 0)
                        {
                            stream.Write(HeaderTypeFactory.CONTENT_LENGTH_BYTES, 0, HeaderTypeFactory.CONTENT_LENGTH_BYTES.Length);
                            stream.Write(result.Length.ToString());
                            stream.Write(HeaderTypeFactory.TOW_LINE_BYTES, 0, 4);
                            result.Write(stream, this);
                        }
                        else
                        {
                            stream.Write(HeaderTypeFactory.CONTENT_LENGTH_BYTES, 0, HeaderTypeFactory.CONTENT_LENGTH_BYTES.Length);
                            MemoryBlockCollection contentLength = stream.Allocate(10);
                            stream.Write(HeaderTypeFactory.TOW_LINE_BYTES, 0, 4);
                            int len = stream.CacheLength;
                            result.Write(stream, this);
                            int count = stream.CacheLength - len;
                            //contentLength.Full("Content-Length: " + count.ToString().PadRight(10) + "\r\n\r\n", stream.Encoding);
                            contentLength.Full(count.ToString().PadRight(10), stream.Encoding);
                        }
                    }
                    else
                    {
                        stream.Write(HeaderTypeFactory.NULL_CONTENT_LENGTH_BYTES, 0, HeaderTypeFactory.NULL_CONTENT_LENGTH_BYTES.Length);
                        stream.Write(HeaderTypeFactory.LINE_BYTES, 0, 2);
                    }
                }
            }
            else
            {
                stream.Write(HeaderTypeFactory.NULL_CONTENT_LENGTH_BYTES, 0, HeaderTypeFactory.NULL_CONTENT_LENGTH_BYTES.Length);
                stream.Write(HeaderTypeFactory.LINE_BYTES, 0, 2);
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Debug))
            {
                Session.Server.Log(EventArgs.LogType.Debug, Session, "{0} {1}", Request.ClientIPAddress, this.ToString());
            }

            if (Session.Server.EnableLog(EventArgs.LogType.Info))
            {
                Session.Server.Log(EventArgs.LogType.Info, Session, "{4} {0} {1} response {2} {3}", Request.Method, Request.Url, Code, CodeMsg, Request.ClientIPAddress);
            }
        }