Exemple #1
0
        bool TryReadAllHeaders() {
            // read the first packet (up to 32K)
            byte[] headerBytes = _connection.ReadRequestBytes(maxHeaderBytes);

            if (headerBytes == null || headerBytes.Length == 0)
                return false;

            if (_headerBytes != null) {
                // previous partial read
                int len = headerBytes.Length + _headerBytes.Length;
                if (len > maxHeaderBytes)
                    return false;

                byte[] bytes = new byte[len];
                Buffer.BlockCopy(_headerBytes, 0, bytes, 0, _headerBytes.Length);
                Buffer.BlockCopy(headerBytes, 0, bytes, _headerBytes.Length, headerBytes.Length);
                _headerBytes = bytes;
            }
            else {
                _headerBytes = headerBytes;
            }

            // start parsing
            _startHeadersOffset = -1;
            _endHeadersOffset = -1;
            _headerByteStrings = new List<ByteString>();

            // find the end of headers
            ByteParser parser = new ByteParser(_headerBytes);

            for (;;) {
                ByteString line = parser.ReadLine();

                if (line == null) {
                    break;
                }

                if (_startHeadersOffset < 0) {
                    _startHeadersOffset = parser.CurrentOffset;
                }

                if (line.IsEmpty) {
                    _endHeadersOffset = parser.CurrentOffset;
                    break;
                }

                _headerByteStrings.Add(line);
            }

            return true;
        }
Exemple #2
0
        private bool TryReadAllHeaders()
        {
            byte[] src = this._conn.ReadRequestBytes(0x8000);
            if ((src == null) || (src.Length == 0))
            {
                return(false);
            }
            if (this._headerBytes != null)
            {
                int num = src.Length + this._headerBytes.Length;
                if (num > 0x8000)
                {
                    return(false);
                }
                byte[] dst = new byte[num];
                Buffer.BlockCopy(this._headerBytes, 0, dst, 0, this._headerBytes.Length);
                Buffer.BlockCopy(src, 0, dst, this._headerBytes.Length, src.Length);
                this._headerBytes = dst;
            }
            else
            {
                this._headerBytes = src;
            }
            this._startHeadersOffset = -1;
            this._endHeadersOffset   = -1;
            this._headerByteStrings  = new ArrayList();
            ByteParser parser = new ByteParser(this._headerBytes);

            while (true)
            {
                ByteString str = parser.ReadLine();
                if (str == null)
                {
                    break;
                }
                if (this._startHeadersOffset < 0)
                {
                    this._startHeadersOffset = parser.CurrentOffset;
                }
                if (str.IsEmpty)
                {
                    this._endHeadersOffset = parser.CurrentOffset;
                    break;
                }
                this._headerByteStrings.Add(str);
            }
            return(true);
        }
Exemple #3
0
        private bool TryReadAllHeaders()
        {
            // read the first packet (up to 32K)
            byte[] headerBytes = _connection.ReadRequestBytes(maxHeaderBytes);
            //Helper.PrintMessage(string.Format("TryReadAllHeaders>>{0}", headerBytes == null ? "null" : headerBytes.Length.ToString()));
            if (headerBytes == null || headerBytes.Length == 0)
                return false;

            if (_headerBytes != null)
            {
                // previous partial read
                int len = headerBytes.Length + _headerBytes.Length;
                if (len > maxHeaderBytes)//限制在32K?
                    return false;

                byte[] bytes = new byte[len];
                Buffer.BlockCopy(_headerBytes, 0, bytes, 0, _headerBytes.Length);
                Buffer.BlockCopy(headerBytes, 0, bytes, _headerBytes.Length, headerBytes.Length);
                _headerBytes = bytes;
            }
            else
            {
                _headerBytes = headerBytes;
            }

            // start parsing
            _startHeadersOffset = -1;
            _endHeadersOffset = -1;
            _headerByteStrings = new List<ByteString>();

            // find the end of headers
            ByteParser parser = new ByteParser(_headerBytes);

            for (; ; )
            {
                ByteString line = parser.ReadLine();

                if (line == null)
                {
                    break;
                }

                if (_startHeadersOffset < 0)
                {
                    _startHeadersOffset = parser.CurrentOffset;
                }

                if (line.IsEmpty)
                {
                    _endHeadersOffset = parser.CurrentOffset;
                    break;
                }

                _headerByteStrings.Add(line);
            }

            return true;
        }
Exemple #4
0
        private bool TryReadAllHeaders()
        {
            // read the first packet (up to 32K)
            byte[] headerBytes = _conn.ReadRequestBytes(maxHeaderBytes);

            if (headerBytes == null || headerBytes.Length == 0)
                return false;

            if (_headerBytes != null) {
                // previous partial read
                int len = headerBytes.Length + _headerBytes.Length;
                if (len > maxHeaderBytes)
                    return false;

                byte[] bytes = new byte[len];
                Buffer.BlockCopy(_headerBytes, 0, bytes, 0, _headerBytes.Length);
                Buffer.BlockCopy(headerBytes, 0, bytes, _headerBytes.Length, headerBytes.Length);
                _headerBytes = bytes;
            }
            else {
                _headerBytes = headerBytes;
            }

            // start parsing
            _startHeadersOffset = -1;
            _endHeadersOffset = -1;
            _headerByteStrings = new ArrayList();

            // find the end of headers
            ByteParser parser = new ByteParser(_headerBytes);

            for (;;) {
                ByteString line = parser.ReadLine();

                if (line == null)
                    break;

                if (_startHeadersOffset < 0) {
                    _startHeadersOffset = parser.CurrentOffset;
                }

                if (line.IsEmpty) {
                    _endHeadersOffset = parser.CurrentOffset;
                    break;
                }

                _headerByteStrings.Add(line);
            }

            return true;
        }
Exemple #5
0
 private bool TryReadAllHeaders()
 {
     byte[] src = this._conn.ReadRequestBytes(0x8000);
     if ((src == null) || (src.Length == 0))
     {
         return false;
     }
     if (this._headerBytes != null)
     {
         int num = src.Length + this._headerBytes.Length;
         if (num > 0x8000)
         {
             return false;
         }
         byte[] dst = new byte[num];
         Buffer.BlockCopy(this._headerBytes, 0, dst, 0, this._headerBytes.Length);
         Buffer.BlockCopy(src, 0, dst, this._headerBytes.Length, src.Length);
         this._headerBytes = dst;
     }
     else
     {
         this._headerBytes = src;
     }
     this._startHeadersOffset = -1;
     this._endHeadersOffset = -1;
     this._headerByteStrings = new ArrayList();
     ByteParser parser = new ByteParser(this._headerBytes);
     while (true)
     {
         ByteString str = parser.ReadLine();
         if (str == null)
         {
             break;
         }
         if (this._startHeadersOffset < 0)
         {
             this._startHeadersOffset = parser.CurrentOffset;
         }
         if (str.IsEmpty)
         {
             this._endHeadersOffset = parser.CurrentOffset;
             break;
         }
         this._headerByteStrings.Add(str);
     }
     return true;
 }