echo_read_request_body

The `echo_read_request_body` directive reads and makes available the request body data within a specified location context.

Syntaxecho_read_request_body;
Defaultnone
Contextlocation, if in location
Argumentsnone

Description

The echo_read_request_body directive is part of the NGINX Echo module, which introduces functionality to work with request and response processing more seamlessly in a configuration context. When this directive is invoked, it reads the request body and stores it for later use, allowing an NGINX server to manipulate the data from the request as needed. This is particularly useful for handling POST requests that contain data in the body, as it allows subsequent commands or configurations to access this data directly.

The directive must be placed within a location or if block where the request body is expected to be read. Upon activation, it does not take any additional arguments, meaning it operates under a simple syntax. Its primary function is to prepare the request body so that it can be accessed via the $echo_request_body variable, which represents the entire body content read from the incoming request. This ability to read and utilize the request body is critical when dealing with APIs or forms submitted via HTTP methods that encapsulate data in the request body.

One potential use case for echo_read_request_body would be in scenarios where applicable operations such as validations, logging, or other processing are necessary on the body content without directly passing it to another application or endpoint. It aids in decoupling request processing from the backend system that would typically handle such data, simplifying NGINX's role as a reverse proxy or load balancer.

Config Example

location /submit {
    echo_read_request_body;
    echo "Received: $echo_request_body";
}

Ensure you are using the correct HTTP method that includes a body, such as POST, as GET and HEAD requests do not typically have a body.

Confirm that the body size does not exceed the configured limits in NGINX, or the body reading may fail silently.

Placement of the directive matters; it must not be nested improperly in contexts that do not support reading the request body.

← Back to all directives