<!-- review: finished -->

<a id="external-unbrotli"></a>

# Unbrotli

The `unbrotli` module is designed for decompressing responses from the
backend that use Brotli compression (`Content-Encoding: br`) for clients
that do not support this compression method. This is particularly useful in
cases where storing data in compressed form on the backend saves space.

<a id="installation-28"></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-unbrotli`
- Angie PRO: `angie-pro-module-unbrotli`

<a id="directives-89"></a>

## Directives

The module provides the following directives:

- `unbrotli` – similar to [gunzip](https://en.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#id1)
- `unbrotli_buffers` – similar to [gunzip_buffers](https://en.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#gunzip-buffers)

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

## Loading the Module

To use the module, it must be loaded in the `main{}` context:

```nginx
load_module modules/ngx_http_unbrotli_filter_module.so;
```

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

## Configuration Example

```nginx
server {
    listen 80 default_server;
    location / {
        root  /usr/share/angie/html;
        index index.html;
    }

    location /storage {
        unbrotli on;
        proxy_pass http://127.0.0.1:8080;
    }
}

# Backend
server {
    listen 8080;
    location /storage {
        root   /usr/share/angie;
        rewrite ^(.*)$ $1.br break;  # Return the compressed file with .br suffix
        add_header Content-Encoding br; # Indicate Brotli compression in the response header
    }
}
```

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

## Demonstration

Let's place the compressed test file `war-and-peace.txt.br`:

```console
$ ls -l /usr/share/angie/storage/
total 2292
-rw-r--r-- 1 root root 1115616 Feb 27 16:10 war-and-peace.txt.br
```

If the client supports Brotli, it will receive the compressed file without decompression:

```console
$ curl -s -H 'Accept-Encoding: br' -o tmp/war-and-peace.txt localhost/storage/war-and-peace.txt

$ ls -l tmp/
total 1092
-rw-r--r-- 1 asv asv 1115616 Feb 27 16:36 war-and-peace.txt
```

If the client does not support Brotli, the `unbrotli` module will decompress the file on the server before sending:

```console
$ curl -s -o tmp/war-and-peace.txt localhost/storage/war-and-peace.txt

$ ls -l tmp/
total 3284
-rw-r--r-- 1 asv asv 3359405 Feb 27 16:39 war-and-peace.txt
```

The file was decompressed by the server before being sent to the client.

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

## Additional Information

Detailed documentation and source code are available at:
[https://github.com/clyfish/ngx_unbrotli](https://github.com/clyfish/ngx_unbrotli).
