Support processing HTTP/1.1 headers as they arrive - #499
Conversation
|
The option and response shape make sense, but there鈥檚 one parsing case to fix before merging. If a socket message ends exactly after a complete header line, such as Could you add tests where a regular header and a trailer end at that boundary, with no byte from the following line, and update the parser to emit them immediately? |
|
@ericmj nice catch! If I'm understanding correctly, this appears to be a quirk of the underlying With that being said, the ideal fix isn't particularly clear to me. If I'm reading RFC 7230 right, I think we could naively check that the incoming data ends with Do you have any suggestions? If not, I'll go with the aforementioned approach. On a related note, do you have insight into whether or not the above behavior is intentional? |
|
one reason might be HTTP1 line folding, a header could have spanned multiple lines, https://www.rfc-editor.org/info/rfc9112/#section-5.2, iex> :erlang.decode_packet(:httph_bin, "header: chunk1\r\n chunk2\r\n\r\n", [])
{:ok, {:http_header, 0, "Header", "header", "chunk1\r\n chunk2"}, "\r\n"}and so when getting |
|
Let's retry the |
|
Pushed the fix recommended by @ericmj. As it turns out, I kept this behavior in order to maintain parity with the underlying functionality, but I'm happy to update at your discretion. |
Introduction
This is my attempt at implementing the feature requested in Issue 452.
The motivation for the change was the
X-ClickHouse-Progressheader system used by the ClickHouse HTTP interface (which I strongly suspect was the reason behind the aforementioned issue).Implementation
This PR adds a new
:stream_headersoption for HTTP/1.1 connections that allows headers and trailers to be emitted as responses as soon as they're available instead of buffering them until they've all arrived. A few nuances about enabling this feature::headersresponses for a given request whereas, when not streaming headers, an empty list would be emitted. This change is explicitly laid out in theMint.HTTPdocumentation.This feature is opt-in, meaning there should be no changes for existing users.
Tesing
All existing tests pass and new stream headers tests were added to the HTTP/1.1 connection test module.
Open to any and all feedback 馃槂