<!-- review: finished -->

<a id="http-slice"></a>

# Slice

The module is a filter that splits a request into subrequests, each returning a certain range of response. The filter provides more effective caching of large responses.

When [building from the source code](https://en.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild),
this module isn't built by default;
it should be enabled with the
`‑‑with‑http_slice_module`
[build option](https://en.angie.software//angie/docs/installation/sourcebuild.md#configure).

In packages and images from [our repos](https://en.angie.software//angie/docs/installation/index.md#install-packages),
the module is included in the build.

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

## Configuration Example

```nginx
location / {
    slice             1m;
    proxy_cache       cache;
    proxy_cache_key   $uri$is_args$args$slice_range;
    proxy_set_header  Range $slice_range;
    proxy_cache_valid 200 206 1h;
    proxy_pass        http://localhost:8000;
}
```

In this example, the response is split into 1-megabyte cacheable slices.

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

## Directives

<a id="index-0"></a>

<a id="id1"></a>

### slice

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `slice` size;          |
|------------------------------------------------------------------------------------------|------------------------|
| Default                                                                                  | `slice 0;`             |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

Sets the size of the slice. The zero value disables splitting responses into slices.

#### WARNING
Note that a too low value may result in excessive memory usage and opening a large number of files.

In order for a subrequest to return the required range, the [$slice_range](#v-slice-range) variable should be passed to the proxied server as the `Range` request header field. If [caching](https://en.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache) is enabled, [$slice_range](#v-slice-range) should be added to the [cache key](https://en.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-key) and caching of responses with 206 status code should be [enabled](https://en.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-valid).

<a id="built-in-variables-10"></a>

## Built-in Variables

<a id="v-slice-range"></a>

### `$slice_range`

The current slice range in [HTTP byte range](https://datatracker.ietf.org/doc/html/rfc7233#section-2.1) format, for example, `bytes=0-1048575`.
