<!-- review: finished -->

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

# Unbrotli

Модуль `unbrotli` предназначен для распаковки ответов от бэкенда,
использующих сжатие Brotli (`Content-Encoding: br`), для клиентов, которые
не поддерживают этот метод сжатия. Это особенно полезно в случаях, когда
хранение данных в сжатом виде на бэкенде позволяет сэкономить место.

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

## Установка

Для [установки](https://angie.software//angie/docs/installation/index.md#install-packages) модуля используйте один из следующих пакетов:

- Angie: `angie-module-unbrotli`;
- Angie PRO: `angie-pro-module-unbrotli`.

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

## Директивы

Модуль предоставляет следующие директивы:

- `unbrotli` – аналогична [gunzip](https://angie.software//angie/docs/configuration/modules/http/http_gunzip.md#id3).
- `unbrotli_buffers` – аналогична [gunzip_buffers](https://angie.software//angie/docs/configuration/modules/http/http_gunzip.md#gunzip-buffers).

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

## Загрузка модуля

Для работы с модулем необходимо загрузить его в контексте `main{}`:

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

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

## Пример конфигурации

```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;
    }
}

# Бэкенд
server {
    listen 8080;
    location /storage {
        root   /usr/share/angie;
        rewrite ^(.*)$ $1.br break;  # Возвращаем сжатый файл с суффиксом .br
        add_header Content-Encoding br; # Указываем Brotli-сжатие в заголовке ответа
    }
}
```

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

## Демонстрация работы

Разместим сжатый тестовый файл `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
```

Если клиент поддерживает Brotli, он получит сжатый файл без декомпрессии:

```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
```

Если клиент не поддерживает Brotli, модуль `unbrotli` разархивирует файл
на сервере перед отправкой:

```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
```

Файл был разархивирован сервером перед отправкой клиенту.

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

## Дополнительная информация

Подробная документация и исходный код доступны по ссылке:
[https://github.com/clyfish/ngx_unbrotli](https://github.com/clyfish/ngx_unbrotli).
