Skip to content

Commit

Permalink
V1F: Readahead for v1f_chunked_*
Browse files Browse the repository at this point in the history
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
nigoroll committed May 31, 2022
1 parent 4bcc99a commit 819a5df
Showing 1 changed file with 231 additions and 79 deletions.
Loading

0 comments on commit 819a5df

Please sign in to comment.