Skip to content

Commit 27eed68

Browse files
authored
Update Decompression.md - drop deflate, mention zstd (#405)
1 parent 0855277 commit 27eed68

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pages/Decompression.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Decompression
22

3-
Many web servers use compression to reduce the size of the payload to speed up delivery to clients, expecting clients to decompress the body of the request. Some of the common compression algorithms used are [gzip], [brotli], [deflate], or no compression at all.
3+
Many web servers use compression to reduce the size of the payload to speed up delivery to clients, expecting clients to decompress the body of the request. Some of the common compression algorithms used are [gzip], [brotli], [zstd], or no compression at all.
44

5-
Clients may specify acceptable compression algorithms through the [`accept-encoding`][accept-encoding] request header. It's common for clients to supply one or more values in `accept-encoding`, for example `accept-encoding: gzip, deflate, identity` in the order of preference.
5+
Clients may specify acceptable compression algorithms through the [`accept-encoding`][accept-encoding] request header. It's common for clients to supply one or more values in `accept-encoding`, for example `accept-encoding: gzip, br` in the order of preference.
66

77
Servers will read the `accept-encoding` and `TE` request headers, and respond appropriately indicating which compression is used in the response body through the [`content-encoding`][content-encoding] or [`transfer-encoding`][transfer-encoding] response headers respectively. It's not as common to use multiple compression algorithms, but it is possible: for example, `content-encoding: gzip` or `content-encoding: br, gzip` (meaning it was compressed with `br` first, and then `gzip`).
88

@@ -44,7 +44,7 @@ defp get_content_encoding_header(headers) do
4444
end
4545
```
4646

47-
We use a combination of `Enum.flat_map/3` and `String.split/3` because the values can be comma-separated and spread over multiple headers. Now we should have a list like `["gzip"]`. We reversed the compression algorithms so that we decompress from the last one to the first one. Let's use this in another function that handles the decompression. Thankfully, Erlang ships with built-in support for gzip and deflate algorithms.
47+
We use a combination of `Enum.flat_map/3` and `String.split/3` because the values can be comma-separated and spread over multiple headers. Now we should have a list like `["gzip"]`. We reversed the compression algorithms so that we decompress from the last one to the first one. Let's use this in another function that handles the decompression. Thankfully, Erlang ships with built-in support for gzip algorithm.
4848

4949
```elixir
5050
defp decompress_data(data, algorithms) do
@@ -54,9 +54,6 @@ end
5454
defp decompress_with_algorithm(gzip, data) when gzip in ["gzip", "x-gzip"],
5555
do: :zlib.gunzip(data)
5656

57-
defp decompress_with_algorithm("deflate", data),
58-
do: :zlib.unzip(data)
59-
6057
defp decompress_with_algorithm("identity", data),
6158
do: data
6259

@@ -87,7 +84,7 @@ Now you can decompress responses! Above is a simple approach to a potentially co
8784

8885
[gzip]: https://tools.ietf.org/html/rfc1952
8986
[brotli]: https://tools.ietf.org/html/rfc7932
90-
[deflate]: https://tools.ietf.org/html/rfc1951
87+
[ztsd]: https://tools.ietf.org/html/rfc8478
9188
[accept-encoding]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
9289
[content-encoding]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
9390
[transfer-encoding]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding

0 commit comments

Comments
 (0)