| 1 |
= cowboy_compress_h(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_compress_h - Compress stream handler |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
The module `cowboy_compress_h` compresses response bodies |
| 10 |
automatically when the client supports it. It will not |
| 11 |
try to compress responses that already have a content |
| 12 |
encoding or that have an etag header defined. |
| 13 |
|
| 14 |
Normal responses will only be compressed when their |
| 15 |
size is lower than the configured threshold. Streamed |
| 16 |
responses are always compressed, including when the |
| 17 |
sendfile command is used. Because the file must be |
| 18 |
read in memory to be compressed, this module is *not* |
| 19 |
suitable for automatically compressing large files. |
| 20 |
|
| 21 |
== Options |
| 22 |
|
| 23 |
[source,erlang] |
| 24 |
---- |
| 25 |
opts() :: #{ |
| 26 |
compress_buffering => boolean(), |
| 27 |
compress_threshold => non_neg_integer() |
| 28 |
} |
| 29 |
---- |
| 30 |
|
| 31 |
Configuration for the compress stream handler. |
| 32 |
|
| 33 |
The default value is given next to the option name: |
| 34 |
|
| 35 |
compress_buffering (false):: |
| 36 |
|
| 37 |
Whether the output will be buffered. By default no |
| 38 |
buffering is done to provide maximum compatibility |
| 39 |
at the cost of a lower compression rate. |
| 40 |
+ |
| 41 |
This option can be updated at any time using the |
| 42 |
`set_options` stream handler command. |
| 43 |
|
| 44 |
compress_threshold (300):: |
| 45 |
|
| 46 |
How large the response body must be to be compressed |
| 47 |
when the response isn't streamed. |
| 48 |
+ |
| 49 |
This option can be updated at any time using the |
| 50 |
`set_options` stream handler command. |
| 51 |
|
| 52 |
== Events |
| 53 |
|
| 54 |
The compress stream handler does not produce any event. |
| 55 |
|
| 56 |
== Changelog |
| 57 |
|
| 58 |
* *2.11*: Compression is now disabled when the etag |
| 59 |
header is in the response headers. |
| 60 |
* *2.11*: The vary: accept-encoding header is now |
| 61 |
always set when this handler is enabled. |
| 62 |
* *2.6*: The options `compress_buffering` and |
| 63 |
`compress_threshold` were added. |
| 64 |
* *2.0*: Module introduced. |
| 65 |
|
| 66 |
== See also |
| 67 |
|
| 68 |
link:man:cowboy(7)[cowboy(7)], |
| 69 |
link:man:cowboy_stream(3)[cowboy_stream(3)], |
| 70 |
link:man:cowboy_decompress_h(3)[cowboy_decompress_h(3)], |
| 71 |
link:man:cowboy_metrics_h(3)[cowboy_metrics_h(3)], |
| 72 |
link:man:cowboy_stream_h(3)[cowboy_stream_h(3)], |
| 73 |
link:man:cowboy_tracer_h(3)[cowboy_tracer_h(3)] |