override_method

The `override_method` directive allows setting or changing the HTTP method of incoming requests based on specified parameters.

Syntaxoverride_method method;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The override_method directive in the NGINX CoolKit Module provides a mechanism to alter the HTTP method of incoming requests dynamically. This can be particularly useful in situations where the desired method is not fixed or to make RESTful API calls that may require different methods depending on parameters provided by the client. The directive takes one or more arguments, where the first argument is typically a variable or a value that decides the method to be applied, and additional methods can be added as required.

In practice, when override_method is invoked, NGINX interprets the specified method(s) to be used for processing the request. This modification occurs prior to forwarding the request to any upstream server or handling it internally, thereby enabling seamless integration with backend services that might expect a specific HTTP method. The methods are expected to be space-separated strings, and the supported methods are defined within the NGINX framework, allowing custom behaviors based on variable content or client input.

Usage of the override_method directive is flexible, as it can be placed in various contexts, including http, server, or location. This versatility ensures that it can be tailored to different parts of configuration files, accommodating specific route requirements or application logic. However, care should be taken to properly configure the method names and ensure they align with what the receiving endpoint can handle.

Config Example

http {
    server {
        location / {
            override_method $arg_method;
            proxy_pass http://127.0.0.1:8100;
        }
    }
}

Ensure the method specified is a valid HTTP method; otherwise, the request may fail.

When using variables, verify that they are correctly set prior to being used to avoid unintended method overrides.

Be cautious with overrides in locations that may require strict method handling, as it can inadvertently expose endpoints to incorrect methods.

← Back to all directives