33

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:

  • size of chunk in hex (D = 13), followed by a CRLF
  • chunk data (All your base), followed by a CRLF

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:

  • of a valid URL that I could ping, which sends trailers in a chunked response? (so that I can confirm whether it's just my test response that's not working); and
  • which clients are known to support (and access/display) trailers sent by the server?
Community
  • 1
  • 1
Scott
  • 1,518
  • 1
  • 15
  • 23
  • Perhaps the question "do any browsers...." is misleading; as I note that a similar question was resolved by the person implementing their own custom HTTP server in Java (http://stackoverflow.com/questions/7851645/how-do-i-send-http-trailers-footers-in-a-chunked-response-from-within-a-java-ser?lq=1). So it's possible that the question should be "do any servers support trailers sent in chunked encoding responses?". – Scott Dec 09 '12 at 07:41
  • As that is paet of the HTTP standard, all browsers that claim to support chunked transfers should support it, surely. So is the problem in your code? What makes you think the browsers are faulty? – Raedwald Sep 24 '13 at 10:54
  • Raedwald: as you will see from my previous comment, I don't necessarily think the browsers are faulty...it's possibly a server-side issue. It certainly could be an issue with my code (I don't doubt that), which is why I was asking for an example URL that does correctly send trailers, which would confirm whether it is my tests that are the problem or not. – Scott Sep 24 '13 at 22:53
  • Scala's spray does sent trailers properly - but except for `telnet` I haven't found any client that supports them. Neither `curl` nor Charles do according to my tests. – Sebastian J. Feb 23 '16 at 16:30

5 Answers5

12

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.

ZachB
  • 13,051
  • 4
  • 61
  • 89
11

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.

Scott
  • 1,518
  • 1
  • 15
  • 23
  • 1
    It looks like browsers have just recently started supporting this - see https://caniuse.com/#search=trailer and [the referenced MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer). Leaves me wondering why, and what the relationship is to HTTP2 features... – brichins Feb 25 '20 at 22:59
3

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 ;)

igr
  • 10,199
  • 13
  • 65
  • 111
  • Me too, haven't seen them in action. And even more exotic haven't seen any chunk parameters. I changed my software and handle both features as malformed responses. – Lothar Apr 16 '14 at 22:31
  • 1
    golang supports http trailers. They use them for their build tool 'gomote': https://www.youtube.com/watch?v=qt_5NswNeHc&feature=youtu.be&t=12m53s – hmalphettes Nov 26 '15 at 03:35
1

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.)
brillout
  • 7,804
  • 11
  • 72
  • 84
  • This is not fully correct: header may be available for inspection via Browser's devtools, but you are unable to read or access it via JavaScript running on pages – It is not possible in any of the problems listed – MDN compatibility table is not detailed enough – see https://github.com/mdn/browser-compat-data/issues/14703 – lidel Jun 30 '23 at 15:53
-1

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.

Pierz
  • 7,064
  • 52
  • 59