Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ The connection pool has been completely redesigned:
- `max_per_host` - Maximum concurrent connections per host (default 50)
- `checkout_timeout` - Timeout to acquire connection slot (default 8000ms)
- `prewarm_count` - Warm connections per host (default 4)
- `auto_decompress` - When `true`, automatically decompresses gzip/deflate responses (#155):
```erlang
{ok, Status, Headers, Body} = hackney:request(get, URL, [], [],
[{with_body, true}, {auto_decompress, true}]).
```
- `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.

### New Functions

Expand Down
35 changes: 35 additions & 0 deletions guides/http_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ ok = hackney:finish_send_body(Ref),
{ok, Body} = hackney:body(Ref).
```

### Automatic Decompression

Hackney can automatically decompress gzip and deflate encoded responses:

```erlang
{ok, 200, Headers, Body} = hackney:get(URL, [], <<>>, [
with_body,
{auto_decompress, true}
]).
```

When `auto_decompress` is enabled:
- Adds `Accept-Encoding: gzip, deflate` header to requests
- Automatically decompresses the response body based on `Content-Encoding`
- Supports gzip, deflate, and x-gzip encodings
- Non-compressed responses are returned unchanged

### Stream Response Body

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

### Stream to Another Process

Use `stream_to` to send async messages to a different process:

```erlang
Receiver = spawn(fun() -> receive_loop() end),
{ok, Ref} = hackney:get(URL, [], <<>>, [
async,
{stream_to, Receiver}
]).
```

When `stream_to` is specified:
- The connection is owned by the `stream_to` process, not the caller
- If `stream_to` dies, the connection terminates
- If the original caller dies, the connection continues as long as `stream_to` is alive
- This ensures proper cleanup when the message recipient terminates

## Connection Pooling

### Default Pool
Expand Down
Loading