echo_after_body
The `echo_after_body` directive allows for the output of additional responses after the body of the HTTP response has been sent to the client.
Description
The echo_after_body directive can be used within an ngx_http_echo context to send additional content after the main body of a response has been delivered. This behavior enables the server to initiate complex response workflows, where headers and body can be manipulated separately. The command associated with this directive can include any valid NGINX directive, allowing powerful customization of the response content.
When this directive is invoked, it allows for further processing of the request even after the main body has been written to the client. For instance, it can be useful in scenarios where certain informational messages or log entries need to be sent after the response has been finalized without holding up the client. By employing this directive, for example, server logs could be generated for an operation while still allowing the client to receive its primary response instantly. This can help improve the perceived performance of a service since the client is not held up waiting for additional tasks to conclude before receiving their requested content.
Config Example
location /example {
echo "Response body sent";
echo_after_body "This message comes after the body";
}Ensure that the main body content is sent before invoking this directive, as it is specifically meant for use after the body has been delivered.
Using echo_after_body with response modifications might lead to unexpected results due to the state of the connection being altered after the body is sent.