$sent_http_link
The $sent_http_link variable contains the value of the Link HTTP response header sent by NGINX.
Description
The $sent_http_link variable is utilized in NGINX when the Link header is set in the response. This variable is particularly relevant for APIs and web services, where providing information on related resources can enhance client-side processing and navigation. It gets populated based on the Link header defined in the response context, typically constructed using multiple URIs that might be relevant to the current resource.
When an HTTP response is generated, if the Link header has been set via configuration or through dynamic settings in Lua, $sent_http_link will contain this value for subsequent processing. It can then be utilized in rewrites, logging, or further response manipulations. Typical values of this variable would be a string representing one or more URIs, often with relations specified (like rel="next" or rel="prev").
This variable is especially useful when implementing pagination in APIs, allowing clients to deduce the next or previous pages easily. By setting the Link header appropriately, NGINX can pass relevant information through the response without needing substantial application logic to handle these references.
Config Example
http {
server {
location /api {
add_header Link "; rel='next'";
}
}
} If the Link header is not set, $sent_http_link will be empty.
Ensure that headers are correctly configured to be sent; this variable only holds a value if the corresponding header is present.