Scott
Scott

Reputation: 1548

Do any browsers support trailers sent in chunked encoding responses?

HTTP/1.1 specifies that a response sent as Transfer-Encoding: chunked can include optional trailers (ie. what would normally be sent as headers, but for whatever reason can't be calculated before the content, so they can be appended to the end), for example:

Request:

GET /trailers.html HTTP/1.1
TE: chunked, trailers

Response:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Trailer: My-Test-Trailer
D\r\n
All your base\r\n
B\r\n;
 are belong\r\n
6\r\n
 to us\r\n
0\r\n
My-Test-Trailer: something\r\n
\r\n

This request specifies in the TE header that it's expecting a chunked response, and will be looking for trailers after the final chunk.

The response specifies in the Trailer header the list of trailers it will be sending (in this case, just one: My-Test-Trailer)

Each of the chunks are sent as:

A zero size chunk (0\r\n) indicates the end of the body.

Then the trailer(s) are specified (My-Test-Trailer: something\r\n), followed by a final CRLF.

Now, from everything I've read so far, trailers are rarely (if ever) used. Most discussions here and elsewhere concerning trailers typically start with "but why do you want to use trailers anyway?".

Putting aside the question of why, out of curiosity I've been trying to simulate a HTTP request/response exchange that uses trailers; but so far I have not yet been able to get it to work, and I'm not sure if it's something wrong with response I'm generating, or whether (as some have suggested) there are simply no clients that look for trailing headers.

Clients I've tried include: curl, wfetch, Chrome + jQuery.

In all cases, the client receives and correctly reconstructs the chunked response (All your base are belong to us); and I can see in the response headers that Trailer: My-Test-Trailer is being sent; but I'm not seeing My-Test-Trailier: something returned either in the response headers, or anywhere. It's unclear whether a trailing header like this should appear in the client as a normal response header, after the entire response has been received and the connection closed?

Interestingly, the curl change logs appear to suggest that curl does support optional trailers, and that curl will process any trailers it finds into the normal header stream.

So does anybody know:

Upvotes: 33

Views: 9417

Answers (5)

Pierz
Pierz

Reputation: 8158

Although not specifically about the use of trailers in chunked mode - in the more general case of Trailers according to caniuse.com, it is claimed that most major browser providers now support the Trailer response header in their latest versions (e.g. Since Firefox-88, Safari-14.1, Chrome-88, etc).

However, it seems that this only due to their support of Server-Timing (which can use trailers as mentioned in another answer), and there does not currently seem to be a general way to access a Trailer header from the browser Javascript.

Trailer support in the Fetch API is currently an open issue, and the request for trailers in Chrome is marked wontfix.

Upvotes: -1

brillout
brillout

Reputation: 7454

As of May 2022, all browsers support the Trailer response header: https://caniuse.com/mdn-http_headers_trailer.

Library support:

  • Node.js
  • Jodd
  • EDIT ME, to add more. (This is a Community wiki answer.)

Upvotes: 1

Scott
Scott

Reputation: 1548

Over 5 years since asking this question, I can now definitively answer it myself.

Mozilla just announced that they will be supporting the new Server-Timing field as a HTTP trailing header (their first ever support for trailers).

https://bugzilla.mozilla.org/show_bug.cgi?id=1413999

However, more importantly, they confirm that it will be whitelisted so that Server-Timing is the only support value (emphasis mine):

Server-Timing is an HTTP trailer, not a header. :mcmanus tells me we currently parse trailers, but then silently throw them away. We don't want to change that behavior in general (we don't want to encourage trailers), so we'll want to whitelist the Server-Timing trailer, store it somewhere (probably even just a mServerTiming header will work for now, since it's the only trailer we support) and then make it available via some new channel.getTrailers() call.

So I guess that confirms it once and for all: trailing headers are not supported (and never likely to be in a general sense) by Moz, and presumably the same stance is taken by all other browser vendors.

Upvotes: 11

ZachB
ZachB

Reputation: 15386

No common browsers support HTTP/1.1 trailers. Look at the column "Headers in trailer" in the "Network" tab of browserscope.

  • Chrome: No, and won't fix (bug). Supports H/2 trailers (bug).
  • Firefox: No, and I don't see a ticket in bugzilla for it. Appears to support H/2.
  • IE: No
  • Edge: No
  • Safari: No
  • Opera: Old versions only (v10 - 12, removed in 14)

As you've discovered, a number of non-browser clients support it.

Upvotes: 13

igr
igr

Reputation: 10624

Since this commit, Jodd HTTP Java client support trailer headers.

On the first question, I haven't yet found any live response that uses them ;)

Upvotes: 3

Related Questions