We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Trailers

Did you think it was a bit odd that we had to write 0\r\n\r\n (two registered nurses) to signal the end of the chunked encoding?

There's actually a good reason for it – you can have additional headers at the end of chunked encoding, called (of course) Trailers. They work the same way that headers do with one catch: you have to specify the names of the trailers in a Trailer header. For example:

HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
Trailer: Lane, Prime, TJ

1E
I could go for a cup of coffee
C
But not Java
12
Never go full Java
0
Lane: goober
Prime: chill-guy
TJ: 1-indexer

They go between the two \r\n sequences in our original chunked encoding example.

Why Trailers?

Trailers are often used to send information about the message body that can't be known until the message body is fully sent. For example, the hash of the message body... in fact, let's do that.

Assignment

  1. Remember, trailers are formatted just like headers.

      • X-Content-SHA256: <hash>
      • X-Content-Length: <length of raw body in bytes>

HTTP header names are case-insensitive by specification. Some servers and clients may canonicalize header names in certain ways (e.g., X-Content-Sha256), so don't be surprised if you notice discrepancies. It's best not to rely on any particular casing when working with headers.

Run and submit the CLI tests with your server running.