Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We maintain a readahead buffer, which gets filled whenever we parse chunk headers and read chunks. The implementation works at the V1F layer only. Because we currently have no way to return, from this layer, data to the HTC pipeline, we must take great care to never over-read the current request. The existing code treats the CR in the CRLF end sequence for chunked encoding as optional, which, in general, leads to a lower safe readahead than if we required CR. For reading chunks, the readahead case is quite trivial: After each chunk, at least one NL needs to follow, plus the last 0 bytes chunk header (0 + NL), plus at least one NL for the end of trailers, totaling to four bytes of safe readahead. In pratice, usually two bytes will be read ahead, the CRLF ending the chunk. For the final chunk, the safe readahead is too conservative to read all of the usual CRLF 0 CRLF CRLF sequence, but the four bytes readahead is sufficient to trigger reading the final zero chunk header, such that we will return VFP_END properly. For reading chunk headers, the minimal safe readahead assumption is for the shortest possible end chunk, 0 NL NL. We very conservatively update the readahead, such that we will usually process a chunk header with two reads.
- Loading branch information