public override HttpPackageInfo ResolvePackage(IBufferStream bufferStream)
        {
            var numLen = (int)(bufferStream.Length - m_HeaderSize - 2);

            bufferStream.Skip(m_HeaderSize);

            var chunkSize = 0;

            for (var i = numLen - 1; i >= 0; i--)
            {
                chunkSize = chunkSize + (int)bufferStream.ReadByte() * (16 ^ i);
            }

            if (chunkSize > 0)
            {
                NextReceiveFilter = new HttpChunkDataReceiveFilter(this, m_HeaderSize + numLen + 2 + chunkSize, chunkSize);
                return(null);
            }

            // last chunk
            var body = m_BodyBuilder.ToString();

            m_BodyBuilder = null;

            return(new HttpPackageInfo("Test", m_HttpHeader, body));
        }
示例#2
0
        private int GetPayloadLength(IBufferStream bufferStream, int length)
        {
            if (length == 2)
            {
                var flag = bufferStream.ReadByte();

                m_Final  = (FINAL_FLAG & flag) == flag;
                m_OpCode = (sbyte)(flag & 0x08);

                // one byte playload length
                var playloadLen = (int)bufferStream.ReadByte();
                //the highest bit is mask indicator
                m_Masked = playloadLen > 128;
                // remove the mask byte
                playloadLen = playloadLen % 128;

                // no extend playload length
                if (playloadLen < 126)
                {
                    if (!m_Masked)
                    {
                        return(playloadLen);
                    }

                    // masking-key: 4 bytes
                    return(playloadLen + 4);
                }

                // playload length takes 2 bytes
                if (playloadLen == 126)
                {
                    ResetSize(4);
                    return(-1);
                }
                else// playload length takes 8 bytes
                {
                    ResetSize(10);
                    return(-1);
                }
            }
            else if (length == 4)
            {
                bufferStream.Skip(2);

                // 2 bytes
                var playloadLen = bufferStream.ReadUInt16();

                if (m_Masked) // add mask key's length
                {
                    playloadLen += 4;
                }

                return(playloadLen);
            }
            else // length = 8
            {
                bufferStream.Skip(2);

                // 8 bytes
                var playloadLen = bufferStream.ReadUInt64();

                if (m_Masked) // add mask key's length
                {
                    playloadLen += 4;
                }

                return((int)playloadLen);
            }
        }
示例#3
0
 protected override int GetBodyLengthFromHeader(IBufferStream bufferStream, int length)
 {
     return(bufferStream.ReadByte());
 }