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); }
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; }