$sent_http_connection
The variable $sent_http_connection holds the value of the 'Connection' header sent to the client in a HTTP response. — NGINX Core (HTTP)
Description
$sent_http_connection is a variable in NGINX that captures the value of the 'Connection' response header that is sent to the client. This header indicates to the client whether the connection to the server should be kept open after the current request is processed. Typical values for this variable might include 'keep-alive' or 'close', depending on the server's configuration and the nature of the connection requested by the client. This variable is primarily useful in scenarios where the server needs to dynamically adjust connection behavior based on the client's request or patterns of usage. For example, if certain clients request persistent connections, the server can respond accordingly. The value of $sent_http_connection is set during the processing of a request, specifically when the response headers are being constructed. The value assigned to this variable is determined by the server's configuration directives within the relevant context. An important point to note is that if the 'Connection' header is not specified in the configuration or if it is not explicitly set during processing, this variable will not contain any value, and thus should be used cautiously in conditional expressions or logging to prevent unintended display of empty headers.
Config Example
server {
listen 80;
location / {
add_header Connection $sent_http_connection;
}
}Subsystem
httpCacheable
YesContexts
http, server, location$sent_http_connection returns an empty string if the 'Connection' header is not set in the response; be cautious when using it in logging or conditionals.
Ensure that the server's connection handling configurations (e.g., persistent connections) are appropriately defined to set this header correctly.