Skip to content

Commit b1c920f

Browse files
authored
docs: add documentation for auto_decompress and stream_to features (#818)
- Update NEWS.md with new options for #155 (auto_decompress) and #646 (stream_to) - Add Automatic Decompression section to HTTP guide - Add Stream to Another Process section to HTTP guide
1 parent 06608b6 commit b1c920f

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ The connection pool has been completely redesigned:
6767
- `max_per_host` - Maximum concurrent connections per host (default 50)
6868
- `checkout_timeout` - Timeout to acquire connection slot (default 8000ms)
6969
- `prewarm_count` - Warm connections per host (default 4)
70+
- `auto_decompress` - When `true`, automatically decompresses gzip/deflate responses (#155):
71+
```erlang
72+
{ok, Status, Headers, Body} = hackney:request(get, URL, [], [],
73+
[{with_body, true}, {auto_decompress, true}]).
74+
```
75+
- `stream_to` - For async requests, the `stream_to` process is now set as the connection owner (#646). If `stream_to` dies, the connection terminates; if the original caller dies, the connection continues as long as `stream_to` is alive.
7076

7177
### New Functions
7278

guides/http_guide.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ ok = hackney:finish_send_body(Ref),
119119
{ok, Body} = hackney:body(Ref).
120120
```
121121

122+
### Automatic Decompression
123+
124+
Hackney can automatically decompress gzip and deflate encoded responses:
125+
126+
```erlang
127+
{ok, 200, Headers, Body} = hackney:get(URL, [], <<>>, [
128+
with_body,
129+
{auto_decompress, true}
130+
]).
131+
```
132+
133+
When `auto_decompress` is enabled:
134+
- Adds `Accept-Encoding: gzip, deflate` header to requests
135+
- Automatically decompresses the response body based on `Content-Encoding`
136+
- Supports gzip, deflate, and x-gzip encodings
137+
- Non-compressed responses are returned unchanged
138+
122139
### Stream Response Body
123140

124141
```erlang
@@ -195,6 +212,24 @@ receive {hackney_response, Ref, Msg} -> ok end,
195212
hackney:stream_next(Ref). %% Request next message
196213
```
197214

215+
### Stream to Another Process
216+
217+
Use `stream_to` to send async messages to a different process:
218+
219+
```erlang
220+
Receiver = spawn(fun() -> receive_loop() end),
221+
{ok, Ref} = hackney:get(URL, [], <<>>, [
222+
async,
223+
{stream_to, Receiver}
224+
]).
225+
```
226+
227+
When `stream_to` is specified:
228+
- The connection is owned by the `stream_to` process, not the caller
229+
- If `stream_to` dies, the connection terminates
230+
- If the original caller dies, the connection continues as long as `stream_to` is alive
231+
- This ensures proper cleanup when the message recipient terminates
232+
198233
## Connection Pooling
199234

200235
### Default Pool

0 commit comments

Comments
 (0)