eval_subrequest_in_memory
The `eval_subrequest_in_memory` directive dictates whether the response from an evaluated subrequest is stored in memory or streamed directly to the client.
Description
The eval_subrequest_in_memory directive is used within the context of an NGINX server's configuration for handling subrequests when utilizing the evaluate module. When set to 'on', it instructs NGINX to keep the content of a subrequest response fully in memory, making it available for later processing within the same request context. This can be particularly useful when dealing with responses that need to be manipulated or conditionally rendered based on the results of the subrequest.
When the directive is set to 'off', NGINX will not store the entire response in memory. Instead, it will pass the chunks of data directly to the client as they are received. This behavior may reduce memory usage but may limit the operations that can be performed on the subrequest data before sending it to the client.
The directive is invoked in HTTP contexts, including global, server, and location configurations, allowing for granular control over response handling based on specific routes or conditions. The flag is defined as a type of integer, allowing for binary values (0 or 1), indicating whether the in-memory behavior is enabled or disabled.
Config Example
location /example {
eval_subrequest_in_memory on;
eval $result {
proxy_pass http://backend;
}
if ($result ~ 'some_condition') {
return 200 'Success';
}
return 404 'Not Found';
}Not storing large responses in memory can lead to unexpected behavior if the responses exceed the defined buffer sizes.
Using this directive with filter modules may require careful ordering of module configuration to ensure the desired output flows correctly.
Setting this directive to 'on' without enough server memory can lead to significant performance degradation due to increased memory usage.