<!-- review: finished -->

<a id="external-set-misc"></a>

# Set-Misc

The `set-misc` module extends the standard functionality of the Rewrite module by adding support for URI escaping and unescaping, JSON quote handling, as well as various encoding and decoding methods (HEX, MD5, SHA1, Base32, Base64) and other operations.

It allows solving the following tasks:

- **URI Processing**: escaping and unescaping URIs.
- **Encoding and Decoding**: support for HEX, MD5, SHA1, Base32, Base64.
- **Additional Functions**: working with JSON quotes and other utility features.

<a id="installation-25"></a>

## Installation

To [install](https://en.angie.software//angie/docs/installation/index.md#install-packages) the module, use one of the following packages:

- Angie: `angie-module-set-misc`
- Angie PRO: `angie-pro-module-set-misc`

<a id="loading-the-module-25"></a>

## Loading the Module

To work with the module, it must be loaded in the context of `main{}`. The example below also uses directives from the [echo](https://en.angie.software//angie/docs/installation/external-modules/echo.md#external-echo) module:

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_set_misc_module.so;
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-99"></a>

## Configuration Example

```nginx
server {
    listen 80;
    server_name localhost;

    location /ifempty {
        set $a $arg_a;
        set_if_empty $a 56;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
    }

    location /unescape {
        set_unescape_uri $a $arg_a;
        set_escape_uri $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }

    location /base32 {
        set_encode_base32 $a $arg_a;
        set_decode_base32 $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }

    location /hex {
        set_encode_hex $a $arg_a;
        set_decode_hex $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }
}
```

<a id="demonstration-2"></a>

## Demonstration

```console
$ curl localhost/ifempty/?a=100

  arg_a = '100'
  a = '100'

$ curl localhost/ifempty

  arg_a = ''
  a = '56'

$ curl localhost/unescape/?a=Hello%20world!

  arg_a = 'Hello%20world!'
  a = 'Hello world!'
  b = 'Hello%20world!'

$ curl localhost/base32/?a=abcde

  arg_a = 'abcde'
  a = 'c5h66p35'
  b = 'abcde'

$ curl localhost/hex/?a=abcde

  arg_a = 'abcde'
  a = '6162636465'
  b = 'abcde'
```

<a id="additional-information-26"></a>

## Additional Information

The full description of directives and source code is available at:
[https://github.com/openresty/set-misc-nginx-module](https://github.com/openresty/set-misc-nginx-module).
