Skip to content

Add gun:trailers/3 for HTTP/1.1 and HTTP/2#359

Open
the-mikedavis wants to merge 1 commit into
ninenines:masterfrom
the-mikedavis:md/trailers
Open

Add gun:trailers/3 for HTTP/1.1 and HTTP/2#359
the-mikedavis wants to merge 1 commit into
ninenines:masterfrom
the-mikedavis:md/trailers

Conversation

@the-mikedavis
Copy link
Copy Markdown

This is a work-in-progress for adding gun:trailers/3. So far I adapted what data/7 is doing in HTTP/1 and HTTP/2 - I still need to look at adding test cases.

Closes #356

@essen
Copy link
Copy Markdown
Member

essen commented Nov 17, 2025

This will need to be made to work with HTTP/3 as well. It likely already works if you do the same as HTTP/2. Tests will confirm. Worst case, using trailers with HTTP/3 should trigger an error (there's plenty of things not implemented with HTTP/3 so if tests show it doesn't work it's fine to error out for now).

@the-mikedavis
Copy link
Copy Markdown
Author

For HTTP/3, a case that errors is probably the easiest (for me at least 😅) for now. It looks like we need to access/update the #http3_state.http3_machine for the QPACK encoding. (I'm pretty familiar with HTTP/2 but not HTTP/3 - maybe this is easier than I am thinking.) gun_http3:data/7 uses cow_http3:data/1 but I think we want to use cow_http3:headers/1 on the headers block from cow_http3_machine:prepare_trailers/3 instead.

@essen
Copy link
Copy Markdown
Member

essen commented Nov 25, 2025

Right if it's not the same as HTTP/2 let's error out for now in gun_http3.

@the-mikedavis the-mikedavis marked this pull request as ready for review April 7, 2026 22:40
@the-mikedavis
Copy link
Copy Markdown
Author

Sorry for the really long delay 😅. I ran into (what I think is?) a bug in cowlib for HTTP/2. I sent a PR over there with the fix, ninenines/cowlib#149.

@the-mikedavis
Copy link
Copy Markdown
Author

the-mikedavis commented Apr 13, 2026

Ultimately I ended up not using this change since I'm targetting S3 and it has a weird content-encoding: aws-chunked which is kind of HTTP/1.1 chunked transfer but not really. You have to send the content-length and include the extra bytes for framing in it, and then also set the true content-length in x-amz-decoded-content-length. https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html / https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming-trailers.html

I think gun:trailers/3 makes sense to have regardless, but it looks like I won't be using it myself directly.

(Surely someone must know why S3 does this weird content encoding thing. I'll go complain 🙂)

Update: it's a purely historical artifact, they invented aws-chunked because HTTP/1.1 chunked transfer+trailers was very immature in HTTP clients at the time. There's really no technical reason you couldn't use standard HTTP/1.1 though, if they allowed it on their end.

@essen
Copy link
Copy Markdown
Member

essen commented Apr 14, 2026

Yes I think it will be good to have in the next release, whenever it happens. I am working on a large H3/WT update for Cowboy that will also be done in Gun and will include other PRs with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support for HTTP/1.1 chunked trailers

2 participants