set_encode_hex

The 'set_encode_hex' directive encodes a variable into hexadecimal format.

Syntaxset_encode_hex variable [destination];
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1-2

Description

The 'set_encode_hex' directive is part of the NGINX Set-Misc module, which provides extended capabilities for handling request variables. This directive takes one or two arguments: the first is the source variable to be encoded, and the optional second argument is the destination variable where the hexadecimal-encoded result will be stored. If the destination variable is not specified, the result will overwrite the source variable. The encoding process transforms each byte of the source variable into its two-character hexadecimal representation. For example, the byte value 0x41 (character 'A') would be encoded as '41'. This transformation is useful in various scenarios, including preparing data for transmission or storage where hexadecimal format is required for data integrity or readability.

Config Example

location /example {
    set $input_variable "test";
    set_encode_hex $input_variable $output_variable;
}

Ensure the destination variable is not already in use, as it will be overwritten if not specified correctly.

Be cautious of variable types; ensure the input variable is a valid string to avoid unintended results.

← Back to all directives