$sent_http_transfer_encoding
$sent_http_transfer_encoding contains the value of the 'Transfer-Encoding' header sent to the client. — NGINX Core (HTTP)
Description
The $sent_http_transfer_encoding variable in NGINX holds the value of the 'Transfer-Encoding' header as sent in the HTTP response to the client. This variable is particularly useful during HTTP responses that use chunked transfer encoding. For a successful assignment of this variable, the NGINX configuration must specify a transfer encoding method, which typically occurs when a dynamic content generation mechanism (like PHP or an upstream server) is in use. When NGINX itself generates a response, the value of this variable may default to an empty string unless specifically set. This variable can take several values, most commonly `chunked`, which denotes that the response will be sent in a series of chunks instead of as a single complete message. This is especially useful for large responses that can be streamed in smaller parts or when the total size of the response is not known beforehand. If no transfer encoding is set by the server, the variable will not contain any value, reflecting that no transfer encoding is in use.
Config Example
location /api {
proxy_pass http://backend;
proxy_set_header Accept-Encoding '';
}
location /stream {
proxy_pass http://stream_backend;
add_header Transfer-Encoding chunked;
}Subsystem
httpCacheable
YesContexts
http, server, location, ifEnsure that the backend service supports and correctly implements chunked transfer encoding to avoid unexpected behavior.
Using $sent_http_transfer_encoding outside the appropriate contexts may yield unexpected or empty results. It is typically used in conjunction with proxy settings.