public bool TakeMessageHeaders(ref SequenceReader <byte> reader, bool trailers) { // Make sure the buffer is limited if (reader.Remaining > _remainingRequestHeadersBytesAllowed) { // Input oversize, cap amount checked return(TrimAndTakeMessageHeaders(ref reader, trailers)); } var alreadyConsumed = reader.Consumed; try { var result = _parser.ParseHeaders(new Http1ParsingHandler(this, trailers), ref reader); if (result) { TimeoutControl.CancelTimeout(); } return(result); } finally { _remainingRequestHeadersBytesAllowed -= reader.Consumed - alreadyConsumed; } bool TrimAndTakeMessageHeaders(ref SequenceReader <byte> reader, bool trailers) { var trimmedBuffer = reader.Sequence.Slice(reader.Position, _remainingRequestHeadersBytesAllowed); var trimmedReader = new SequenceReader <byte>(trimmedBuffer); try { if (!_parser.ParseHeaders(new Http1ParsingHandler(this, trailers), ref trimmedReader)) { // We read the maximum allowed but didn't complete the headers. KestrelBadHttpRequestException.Throw(RequestRejectionReason.HeadersExceedMaxTotalSize); } TimeoutControl.CancelTimeout(); reader.Advance(trimmedReader.Consumed); return(true); } finally { _remainingRequestHeadersBytesAllowed -= trimmedReader.Consumed; } } }
public bool TakeMessageHeaders(ReadableBuffer buffer, out ReadCursor consumed, out ReadCursor examined) { // Make sure the buffer is limited bool overLength = false; if (buffer.Length >= _remainingRequestHeadersBytesAllowed) { buffer = buffer.Slice(buffer.Start, _remainingRequestHeadersBytesAllowed); // If we sliced it means the current buffer bigger than what we're // allowed to look at overLength = true; } var result = _parser.ParseHeaders(new Http1ParsingHandler(this), buffer, out consumed, out examined, out var consumedBytes); _remainingRequestHeadersBytesAllowed -= consumedBytes; if (!result && overLength) { ThrowRequestRejected(RequestRejectionReason.HeadersExceedMaxTotalSize); } if (result) { TimeoutControl.CancelTimeout(); } return(result); }