$sent_trailer_*
The $sent_trailer_ variable is a prefix variable used to retrieve trailers sent with HTTP responses in NGINX. — NGINX Core (HTTP)
Description
The $sent_trailer_ variable is used in conjunction with HTTP/1.1 responses that include trailers, which are additional fields sent after the message body. This variable allows NGINX to access specific trailer fields that may have been set in the response. It can be prefixed to a trailer name, such as `$sent_trailer_myfield`, which would return the value of the `myfield` trailer if it was specified in the HTTP response. Typically, this variable is set during the HTTP response phase when the trailers have been determined and are ready to be sent. The trailers themselves are defined in the response header fields, and thus, the values associated with the $sent_trailer_ variables will depend on how the application or backend service populates these trailer fields before NGINX sends the final response. If the specified trailer exists, the variable will return its value; otherwise, it will return an empty string. The usage of trailers is not widely common in front-end server responses, and their support largely depends on the client and server implementations. Some use cases of trailers include providing checksum data or other metadata that should come after the payload in streaming scenarios, making the trailers a useful feature for specific applications.
Config Example
location /example {
add_header My-Trailer myvalue;
# The value of the trailer can be accessed
echo "$sent_trailer_My-Trailer";
}Subsystem
httpCacheable
YesType
Prefix variableContexts
http, server, locationIf the specified trailer does not exist, accessing the variable will return an empty string, which can lead to confusion when debugging.
Ensure that the backend actually sends trailer headers; otherwise, this variable will have no value.
Remember that not all clients support HTTP trailers, which may limit your use cases.