Packages
hackney
4.9.1
4.12.4
4.12.3
4.12.2
4.12.1
4.12.0
4.11.1
4.11.0
4.10.2
4.10.1
4.10.0
4.9.1
4.9.0
4.8.7
4.8.6
4.8.5
4.8.4
4.8.3
4.8.2
4.8.1
4.8.0
4.7.4
4.7.3
4.7.2
4.7.1
4.7.0
4.6.1
4.6.0
4.5.2
4.5.1
4.5.0
4.4.5
4.4.3
4.4.2
4.4.1
4.4.0
4.3.0
4.2.3
4.2.2
4.2.1
4.2.0
4.1.0
4.0.3
4.0.2
4.0.1
4.0.0
3.2.1
3.2.0
3.1.2
3.1.1
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
retired
2.0.1
2.0.0
2.0.0-beta.1
1.25.0
1.24.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.1
1.20.0
1.19.1
1.19.0
1.18.2
1.18.1
1.18.0
1.17.4
1.17.3
1.17.2
1.17.1
1.17.0
1.16.0
1.15.2
1.15.1
1.15.0
1.14.3
1.14.2
1.14.0
1.13.0
1.12.1
1.12.0
1.11.0
1.10.1
1.10.0
1.9.0
1.8.6
1.8.5
1.8.4
1.8.3
1.8.2
1.8.0
1.7.1
1.7.0
1.6.6
retired
1.6.5
1.6.4
retired
1.6.3
1.6.2
1.6.1
1.6.0
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.10
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.0
1.1.0
1.0.6
1.0.5
1.0.2
1.0.1
0.15.2
0.15.0
0.14.3
0.14.2
0.14.1
0.14.0
0.13.1
Simple HTTP client with HTTP/1.1, HTTP/2, and HTTP/3 support
Current section
138 Versions
Jump to
Current section
138 Versions
Compare versions
18
files changed
+807
additions
-161
deletions
| @@ -1,5 +1,270 @@ | |
| 1 1 | # NEWS |
| 2 2 | |
| 3 | + 4.9.1 - 2026-10-26 |
| 4 | + ------------------ |
| 5 | + |
| 6 | + ### Fixed |
| 7 | + |
| 8 | + - The documentation builds again. A misplaced doc comment in 4.9.0 made |
| 9 | + edoc fail, which also blocked publishing that release to Hex. |
| 10 | + |
| 11 | + 4.9.0 - 2026-10-25 |
| 12 | + ------------------ |
| 13 | + |
| 14 | + ### Added |
| 15 | + |
| 16 | + - A `max_body_size` request option caps a response body that hackney |
| 17 | + buffers for you (the default `hackney:request` result, or `body/1`). |
| 18 | + It defaults to 512 MiB and also accepts the 1.x name `max_body`; |
| 19 | + `infinity` turns it off (#980). |
| 20 | + |
| 21 | + ### Fixed |
| 22 | + |
| 23 | + - URLs that hide a loopback or private IP inside a percent-encoded |
| 24 | + bracketed IPv6 address, or behind a trailing dot, are now refused like |
| 25 | + other IP literals. The earlier fix for CVE-2026-47076 missed these two |
| 26 | + spellings, so such a URL still reached the address it denotes (#987). |
| 27 | + - Pinning your own CA with `cacerts` or `cacertfile` now actually limits |
| 28 | + which servers are trusted. hackney still accepted any certificate chain |
| 29 | + that included a publicly trusted root, so a pinned connection could reach |
| 30 | + a server its CA never vouched for (#978). |
| 31 | + - Following a redirect no longer resends `basic_auth` and `cookie` to |
| 32 | + another port on the same host, or over plain HTTP after HTTPS. Only a |
| 33 | + redirect to the same scheme, host and port keeps them, unless you set |
| 34 | + `location_trusted` (#979). |
| 35 | + - A server sending an endless or highly compressed body can no longer |
| 36 | + exhaust memory. Buffered bodies had no limit on HTTP/1.1, HTTP/2 and |
| 37 | + HTTP/3, and `auto_decompress` inflated the whole body at once. Both now |
| 38 | + stop at `max_body_size` with `{error, body_too_large}` (#980). |
| 39 | + - HTTPS proxies reached through CONNECT now get the same certificate checks |
| 40 | + as the target: hackney's CA bundle and a hostname check against the |
| 41 | + proxy. The connection to the proxy only set the server name, so on |
| 42 | + OTP 27 and later it failed unless `proxy_ssl_options` set `cacerts` or |
| 43 | + `verify_none`. An explicit `{verify, verify_none}` is still honoured (#988). |
| 44 | + - A `proxy_auth_fun` that returns a value containing CR, LF or NUL is now |
| 45 | + refused with `{error, {proxy_auth_error, invalid_header}}`. The value was |
| 46 | + written as is into the CONNECT request, so those bytes added header lines |
| 47 | + of their own (#989). |
| 48 | + - A slow or unreachable host no longer stalls every request that goes |
| 49 | + through the same pool. The pool opened new connections itself, so while |
| 50 | + one host took its time to answer, checkouts for every other host waited, |
| 51 | + for up to `connect_timeout`. The requester now opens its own connection, |
| 52 | + as in hackney 1.x (#973). |
| 53 | + - A failed TLS handshake on a pooled connection no longer frees a |
| 54 | + `max_per_host` slot held by another request. The slot was released twice, |
| 55 | + so the host could get one more concurrent connection than allowed (#984). |
| 56 | + |
| 57 | + ### Changed |
| 58 | + |
| 59 | + - Buffered downloads over 512 MiB now fail with `{error, body_too_large}` |
| 60 | + unless you raise `max_body_size` (#980). |
| 61 | + - If you pin `cacerts` that include the bundled public roots, hackney no |
| 62 | + longer falls back to trusting a cross-signed root it finds in the |
| 63 | + server's chain. Add the root you need to your list, or pass your own |
| 64 | + `partial_chain` (#978). |
| 65 | + |
| 66 | + 4.8.7 - 2026-10-25 |
| 67 | + ------------------ |
| 68 | + |
| 69 | + ### Changed |
| 70 | + |
| 71 | + - Update `quic` to 2.1.2, a security release for HTTP/3 and WebTransport. |
| 72 | + Session tickets now resume only on the listener that issued them, and a |
| 73 | + hostile peer can no longer stall a listener or grow a slow owner's |
| 74 | + mailbox without bound (#982). |
| 75 | + |
| 76 | + 4.8.6 - 2026-10-24 |
| 77 | + ------------------ |
| 78 | + |
| 79 | + ### Fixed |
| 80 | + |
| 81 | + - Large HTTP/2 downloads over slow links no longer fail with |
| 82 | + `{error, {stream_error, internal_error}}`. hackney let only 64 KB of a |
| 83 | + response travel per round trip, so over a 120 ms link a 40 MB body took |
| 84 | + longer than the server allowed and the server cancelled it. HTTP/2 |
| 85 | + downloads now run about as fast as HTTP/1.1 (#976). |
| 86 | + - Closing a pooled TLS connection no longer logs a supervisor report with |
| 87 | + reason `killed`. The connection waited for the server to close its side, |
| 88 | + which took longer than the pool allows, and was killed (#976). |
| 89 | + |
| 90 | + ### Changed |
| 91 | + |
| 92 | + - Update `h2` to 0.12.5 and `certifi` to 2.18.0. The new `certifi` removes |
| 93 | + the compromised eMudhra certificates from the CA bundle (#975). |
| 94 | + |
| 95 | + 4.8.5 - 2026-10-04 |
| 96 | + ------------------ |
| 97 | + |
| 98 | + ### Fixed |
| 99 | + |
| 100 | + - A GOAWAY fails only the requests the server refused. HTTP/2 failed every |
| 101 | + in-flight request with `{error, {goaway, _}}`, including ones the server |
| 102 | + went on to complete, and HTTP/3 ignored the GOAWAY and kept sending new |
| 103 | + requests on the connection. Accepted streams now finish, streamed uploads |
| 104 | + and responses included, refused ones fail and are reset, and the |
| 105 | + connection leaves the pool and closes once drained (#961, #962, #964, |
| 106 | + #965, #968). |
| 107 | + - A failed HTTP/2 request body send fails the other streams on the |
| 108 | + connection instead of leaving them waiting (#964). |
| 109 | + - Closing an HTTP/3 connection no longer makes the other live HTTP/3 |
| 110 | + connections unreachable. The connection table was owned by the first |
| 111 | + connection and went away with it (#967). |
| 112 | + |
| 113 | + ### Changed |
| 114 | + |
| 115 | + - Update `h2` to 0.12.4, `quic` to 2.1.1 and `webtransport` to 0.4.8. |
| 116 | + |
| 117 | + 4.8.4 - 2026-09-27 |
| 118 | + ------------------ |
| 119 | + |
| 120 | + ### Fixed |
| 121 | + |
| 122 | + - `hackney:close/1` on a shared pooled HTTP/2 connection resets only the |
| 123 | + caller's own streams. It stopped the connection, failing every other |
| 124 | + caller's streams on it. The connection still closes itself once idle with |
| 125 | + no stream open. |
| 126 | + - A connection opened without a pool honours `connect_timeout` above 8 |
| 127 | + seconds, and a dial that outlives it returns `{error, connect_timeout}`. |
| 128 | + The wait was capped at 8 seconds and ended as an exit in the caller. A |
| 129 | + dial stuck in the transport no longer holds the caller past its deadline |
| 130 | + either (#945). |
| 131 | + |
| 132 | + 4.8.3 - 2026-09-27 |
| 133 | + ------------------ |
| 134 | + |
| 135 | + ### Fixed |
| 136 | + |
| 137 | + - `hackney_conn:set_owner/2` works while a streamed request body is being |
| 138 | + sent. It returned `{error, invalid_state}`. |
| 139 | + - A response body cut short by the server closing the connection is an |
| 140 | + error. For a chunked or `Content-Length` body, `body/1` returns |
| 141 | + `{error, {closed, Partial}}` with the bytes that arrived, and |
| 142 | + `stream_body/1` and async responses end with `{error, closed}`. They |
| 143 | + reported a short body as complete. A body with neither still ends when the |
| 144 | + connection closes. |
| 145 | + - An HTTPS request through a CONNECT proxy reached over TLS |
| 146 | + (`{proxy_transport, ssl}`) works. The target TLS handshake ran over the |
| 147 | + proxy TLS socket as if it were plain TCP and failed. |
| 148 | + - A pooled connection from `hackney:connect/*` stays with its caller between |
| 149 | + requests, and `hackney:close/1` checks it back into the pool. It went back |
| 150 | + to the pool after every response while the caller still used it, so the |
| 151 | + pool could stop it in the middle of the next request (`{error, closed}`) |
| 152 | + or lend it to another process. |
| 153 | + |
| 154 | + 4.8.2 - 2026-09-26 |
| 155 | + ------------------ |
| 156 | + |
| 157 | + ### Fixed |
| 158 | + |
| 159 | + - A connection opened without a pool is owned by the process that opened it |
| 160 | + and closes when that process dies. It was started under `hackney_conn_sup` |
| 161 | + and owned by it, so a killed caller left the connection and its socket open |
| 162 | + until the server closed it (`idle_timeout` defaults to `infinity`). Covers |
| 163 | + `request/5` and `connect/*` with `{pool, false}`, streamed request bodies, |
| 164 | + async responses, HTTP proxies, CONNECT and SOCKS5 tunnels, HTTP/2 and |
| 165 | + HTTP/3, and `h2_open/*` streams. With `stream_to`, the `stream_to` process |
| 166 | + owns the connection, as before. `hackney_conn:set_owner/2` still moves |
| 167 | + ownership. |
| 168 | + - An HTTP/1.1 connection waiting for a response closes within a second of |
| 169 | + its owner dying. It was blocked in the socket read and noticed only when |
| 170 | + the response came, the server closed, or `recv_timeout` expired. |
| 171 | + - A CONNECT or SOCKS5 tunnel socket belongs to its connection. It stayed with |
| 172 | + the process that opened it, so after `hackney_conn:set_owner/2` it still |
| 173 | + closed when that process died. |
| 174 | + |
| 175 | + 4.8.1 - 2026-09-25 |
| 176 | + ------------------ |
| 177 | + |
| 178 | + ### Changed |
| 179 | + |
| 180 | + - Update `quic` to 2.0.1, which compiles on Windows again. Its NIF build and |
| 181 | + clean hooks ran through `sh`, which Windows lacks, so the compile failed |
| 182 | + there for anything that reaches quic, hackney included. Windows runs on OTP |
| 183 | + crypto. |
| 184 | + |
| 185 | + 4.8.0 - 2026-09-24 |
| 186 | + ------------------ |
| 187 | + |
| 188 | + ### Fixed |
| 189 | + |
| 190 | + - `hackney:send_request/2` works on HTTP/2 and HTTP/3. Those protocols answer |
| 191 | + a request with the body included, which the function did not handle, so it |
| 192 | + failed with a `case_clause`. It returns the connection on every protocol |
| 193 | + now, so the response is read with `body/1` or pulled with `stream_body/1`. |
| 194 | + - Several callers reading responses on one HTTP/2 or HTTP/3 connection each |
| 195 | + get their own. The read was resolved from the connection's last stream |
| 196 | + rather than the caller's, so on HTTP/2 all but one caller got |
| 197 | + `{error, no_stream}`, and on HTTP/3 two callers could be handed each |
| 198 | + other's body. |
| 199 | + - A caller reading an HTTP/3 response with `body/1` or `stream_body/1` is |
| 200 | + answered when the server resets its stream, instead of waiting for its own |
| 201 | + timeout. Needs quic 2.0.0, the first release to report a peer RESET_STREAM. |
| 202 | + - A pooled HTTP/2 connection no longer closes when the caller that opened it |
| 203 | + exits. It stayed owned by that caller, so its exit failed every other |
| 204 | + caller's request on the connection with `{error, closed}`. A shared |
| 205 | + connection now has no owner: each stream is tied to its own caller and is |
| 206 | + reset if that caller dies, and the connection closes itself once it has had |
| 207 | + no open stream for the pool `timeout` (#937, thanks @smartinio). |
| 208 | + - Unregistering a pooled HTTP/2 connection no longer leaks its per-host slot. |
| 209 | + The pool dropped its monitor on the connection, so the slot was never |
| 210 | + released when the connection stopped. |
| 211 | + - A response that crosses a reset of its stream no longer closes the HTTP/2 |
| 212 | + connection. `h2` dropped the header block of that response without decoding |
| 213 | + it, so the next response on the connection failed with COMPRESSION_ERROR. |
| 214 | + - The response to an HTTP/3 streaming upload can be read. After |
| 215 | + `start_response/1`, `body/1` returned `{error, invalid_state}` and |
| 216 | + `stream_body/1` returned `{error, no_stream}`: the body went to the |
| 217 | + `start_response/1` caller as a second reply and was lost. When the response |
| 218 | + headers arrived before `start_response/1` was called, it could wait forever. |
| 219 | + - HTTP/3 response headers carry one `:status`. quic_h3 passes the status |
| 220 | + separately and keeps it in the header list, and hackney prepended its own, |
| 221 | + so every response reached the low-level `{h3, _, {stream_headers, ...}}` |
| 222 | + consumer with the pseudo-header twice, which RFC 9114 4.3.1 makes a |
| 223 | + malformed response. Requests through `hackney:request/5` were not affected: |
| 224 | + pseudo-headers are filtered before the caller sees them. |
| 225 | + - An HTTP/3 connection that goes away reports why. `quic_h3` sends the reason |
| 226 | + with its close event, and the handler only matched the older shape without |
| 227 | + one, so the message was dropped: the caller waited out its own timeout and |
| 228 | + the connection process stayed alive. A handshake that fails on a bad |
| 229 | + certificate or a TLS alert now comes back as that error instead of |
| 230 | + `{error, timeout}`. |
| 231 | + - `hackney_h3:connect/3,4` and `hackney_h3:request/5` honor a `cacertfile` |
| 232 | + option. It was handed to quic, which only takes DER `cacerts`, so it was |
| 233 | + ignored and verification failed as `{error, timeout}`. `hackney:request/5` |
| 234 | + was not affected. |
| 235 | + - Connection-specific headers are dropped from HTTP/2 and HTTP/3 requests. |
| 236 | + A caller's `Connection: keep-alive`, legal in HTTP/1.1 and banned by |
| 237 | + RFC 9113 8.2.2 and RFC 9114 4.2, reached the header block and every request |
| 238 | + failed before anything was written. hackney picks the protocol through ALPN, |
| 239 | + so the caller cannot know which rules apply: `Connection`, `Keep-Alive`, |
| 240 | + `Proxy-Connection`, `Transfer-Encoding` and `Upgrade` are stripped alongside |
| 241 | + `Host`. `TE` is kept, being allowed with the value `trailers` |
| 242 | + (#935, thanks @lennartschoch). |
| 243 | + - A pooled HTTP/1.1 connection handed to a requester no longer closes itself |
| 244 | + under the request. Checkout left the keepalive timer running, armed before |
| 245 | + the readiness probe, so a connection could pass the probe and then fire the |
| 246 | + timer, and the request that followed came back as `{error, invalid_state}`. |
| 247 | + The timer is disarmed on checkout and re-armed when the connection returns |
| 248 | + to the pool (#934, thanks @lennartschoch). |
| 249 | + - A request that races a peer-initiated close now returns `{error, closed}` |
| 250 | + instead of `{error, invalid_state}`. A connection that sees the peer close |
| 251 | + stays alive briefly so late calls get an answer, and during that window every |
| 252 | + call without a handler answered with the generic `invalid_state`. The same |
| 253 | + race therefore had two answers: `{error, closed}` once the connection process |
| 254 | + was gone, `{error, invalid_state}` while it lingered. Callers can now tell a |
| 255 | + closed connection from a misuse of the API (#932, #933, thanks @kpy3). |
| 256 | + |
| 257 | + ### Changed |
| 258 | + |
| 259 | + - Update `h2` to 0.12.3. 0.12.3 sends the DATA already buffered on a stream |
| 260 | + when a SETTINGS frame raises the initial window, so a request body queued |
| 261 | + against a zero window no longer stalls until an unrelated WINDOW_UPDATE |
| 262 | + arrives. |
| 263 | + - Update `quic` to 2.0.0 and `webtransport` to 0.4.7. quic 2.0.0 reports a |
| 264 | + peer resetting a request stream, always sends a reason with its HTTP/3 |
| 265 | + close event, and fixes a handshake that could stall when resuming from a |
| 266 | + cached session ticket. |
| 267 | + |
| 3 268 | 4.7.4 - 2026-08-12 |
| 4 269 | ------------------ |
| @@ -90,7 +90,7 @@ Each connection is a `gen_statem` process that manages: | |
| 90 90 | |
| 91 91 | ### Owner Monitoring |
| 92 92 | |
| 93 | - The connection process monitors its owner (the process that checked out the connection). If the owner crashes, the connection terminates automatically, preventing socket leaks. |
| 93 | + The connection process monitors its owner: the process that checked out the connection, or for a connection opened without a pool, the process that opened it (with `stream_to`, the `stream_to` process once the async request starts). If the owner crashes, the connection terminates automatically, preventing socket leaks. An HTTP/1.1 read waiting on the server checks for this every second. `hackney_conn:set_owner/2` moves ownership to another process. |
| 94 94 | |
| 95 95 | ```erlang |
| 96 96 | %% When connection is checked out |
| @@ -258,6 +258,8 @@ end) || Path <- Paths]. | |
| 258 258 | 2. **Connection sharing** - Unlike HTTP/1.1, HTTP/2 connections are not "checked out" exclusively; multiple callers share the same connection |
| 259 259 | 3. **Stream isolation** - Each request gets a unique StreamId; responses are routed back to the correct caller via the `h2_streams` map |
| 260 260 | 4. **Automatic registration** - When a new SSL connection negotiates HTTP/2, it's automatically registered in the pool for future reuse |
| 261 | + 5. **No single owner** - A shared connection does not belong to the process that opened it. If a caller exits, only its own stream is reset; the other callers' requests continue |
| 262 | + 6. **Idle close** - A shared connection closes itself once it has had no open stream for the pool `timeout`, and the next request opens a new one |
| 261 263 | |
| 262 264 | ## Server Push |
| 263 265 | |
| @@ -300,6 +302,13 @@ Each chunk is sent as a DATA frame and the request stream is closed with | |
| 300 302 | END_STREAM on `finish_send_body/1`. The `h2` connection buffers beyond the |
| 301 303 | peer's flow-control window and drains as WINDOW_UPDATEs arrive. |
| 302 304 | |
| 305 | + A streaming upload uses its pooled connection on its own. From |
| 306 | + `hackney:request/5` with `stream` until `start_response/1`, the connection |
| 307 | + takes no new requests: requests to the same host in the meantime open another |
| 308 | + connection, and streams already open on it are not affected. `send_body/2` |
| 309 | + and `finish_send_body/1` find the upload through the connection pid, so two |
| 310 | + uploads cannot share one connection. |
| 311 | + |
| 303 312 | ## Bidirectional Streaming (gRPC-style) |
| 304 313 | |
| 305 314 | For full-duplex streams, where the client sends and receives on the same |
| @@ -161,6 +161,19 @@ When `auto_decompress` is enabled: | |
| 161 161 | - Automatically decompresses the response body based on `Content-Encoding` |
| 162 162 | - Supports gzip, deflate, and x-gzip encodings |
| 163 163 | - Non-compressed responses are returned unchanged |
| 164 | + - The decompressed body counts against `max_body_size` (see below) |
| 165 | + |
| 166 | + ### Response Body Size Limit |
| 167 | + |
| 168 | + A response body returned whole (`hackney:request/5`, `hackney:body/1`) is |
| 169 | + capped at 512 MiB, measured after decompression. Past the cap the request |
| 170 | + fails with `{error, body_too_large}` instead of buffering the body in memory. |
| 171 | + Set `max_body_size` to change the cap, or `infinity` to disable it; for very |
| 172 | + large downloads use the streaming API instead. |
| 173 | + |
| 174 | + ```erlang |
| 175 | + hackney:get(URL, [], <<>>, [{max_body_size, 10 * 1024 * 1024}]). |
| 176 | + ``` |
| 164 177 | |
| 165 178 | ### Stream Response Body (Async Mode) |
| 166 179 | |
| @@ -325,12 +338,27 @@ Protocol = hackney_conn:get_protocol(ConnPid). %% http1 | http2 | http3 | |
| 325 338 | ### Send Requests on the Connection |
| 326 339 | |
| 327 340 | ```erlang |
| 328 | - %% Send multiple requests on the same connection |
| 329 | - {ok, 200, Headers1, Body1} = hackney:send_request(ConnPid, {get, <<"/api/users">>, [], <<>>}). |
| 330 | - {ok, 201, Headers2, Body2} = hackney:send_request(ConnPid, {post, <<"/api/users">>, |
| 341 | + %% Send multiple requests on the same connection. send_request returns the |
| 342 | + %% connection; read each response before sending the next one. |
| 343 | + {ok, 200, Headers1, ConnPid} = hackney:send_request(ConnPid, {get, <<"/api/users">>, [], <<>>}). |
| 344 | + {ok, Body1} = hackney:body(ConnPid). |
| 345 | + |
| 346 | + {ok, 201, Headers2, ConnPid} = hackney:send_request(ConnPid, {post, <<"/api/users">>, |
| 331 347 | [{<<"content-type">>, <<"application/json">>}], |
| 332 348 | <<"{\"name\": \"Alice\"}">>}). |
| 333 | - {ok, 200, Headers3, Body3} = hackney:send_request(ConnPid, {get, <<"/api/users/1">>, [], <<>>}). |
| 349 | + {ok, Body2} = hackney:body(ConnPid). |
| 350 | + ``` |
| 351 | + |
| 352 | + Pull a response in chunks instead of reading it whole: |
| 353 | + |
| 354 | + ```erlang |
| 355 | + {ok, 200, _Headers, ConnPid} = hackney:send_request(ConnPid, {get, <<"/big">>, [], <<>>}). |
| 356 | + stream_loop(ConnPid) -> |
| 357 | + case hackney:stream_body(ConnPid) of |
| 358 | + {ok, Chunk} -> handle(Chunk), stream_loop(ConnPid); |
| 359 | + done -> ok; |
| 360 | + {error, R} -> {error, R} |
| 361 | + end. |
| 334 362 | ``` |
| 335 363 | |
| 336 364 | ### Close the Connection |
| @@ -339,6 +367,16 @@ Protocol = hackney_conn:get_protocol(ConnPid). %% http1 | http2 | http3 | |
| 339 367 | hackney:close(ConnPid). |
| 340 368 | ``` |
| 341 369 | |
| 370 | + A connection from a pool stays yours between requests; it does not go back to the pool after each response. `hackney:close/1` returns it to the pool when it can be reused, and closes it otherwise. A pooled HTTP/2 connection is shared with other callers: `hackney:close/1` only resets your own streams on it. |
| 371 | + |
| 372 | + ### Hand the Connection to Another Process |
| 373 | + |
| 374 | + A connection opened without a pool belongs to the process that opened it and closes when that process exits. To keep it open after that, give it to the process that will use it: |
| 375 | + |
| 376 | + ```erlang |
| 377 | + ok = hackney_conn:set_owner(ConnPid, NewOwner). |
| 378 | + ``` |
| 379 | + |
| 342 380 | ### Complete Example |
| 343 381 | |
| 344 382 | ```erlang |
| @@ -351,10 +389,11 @@ case hackney_conn:get_protocol(Conn) of | |
| 351 389 | http1 -> io:format("Using HTTP/1.1 keep-alive~n") |
| 352 390 | end, |
| 353 391 | |
| 354 | - %% Make requests |
| 355 | - {ok, 200, _, Token} = hackney:send_request(Conn, {post, <<"/auth">>, [], Credentials}), |
| 356 | - {ok, 200, _, Users} = hackney:send_request(Conn, {get, <<"/users">>, AuthHeaders, <<>>}), |
| 357 | - {ok, 200, _, Data} = hackney:send_request(Conn, {get, <<"/data">>, AuthHeaders, <<>>}), |
| 392 | + %% Make requests, reading each body before the next request |
| 393 | + {ok, 200, _, Conn} = hackney:send_request(Conn, {post, <<"/auth">>, [], Credentials}), |
| 394 | + {ok, Token} = hackney:body(Conn), |
| 395 | + {ok, 200, _, Conn} = hackney:send_request(Conn, {get, <<"/users">>, AuthHeaders, <<>>}), |
| 396 | + {ok, Users} = hackney:body(Conn), |
| 358 397 | |
| 359 398 | %% Clean up |
| 360 399 | hackney:close(Conn). |
| @@ -41,11 +41,11 @@ | |
| 41 41 | [{<<"certifi">>, |
| 42 42 | [{<<"app">>,<<"certifi">>}, |
| 43 43 | {<<"optional">>,false}, |
| 44 | - {<<"requirement">>,<<"~>2.17.0">>}]}, |
| 44 | + {<<"requirement">>,<<"~>2.18.0">>}]}, |
| 45 45 | {<<"h2">>, |
| 46 46 | [{<<"app">>,<<"h2">>}, |
| 47 47 | {<<"optional">>,false}, |
| 48 | - {<<"requirement">>,<<"~>0.12.0">>}]}, |
| 48 | + {<<"requirement">>,<<"~>0.12.5">>}]}, |
| 49 49 | {<<"idna">>, |
| 50 50 | [{<<"app">>,<<"idna">>}, |
| 51 51 | {<<"optional">>,false}, |
| @@ -58,6 +58,10 @@ | |
| 58 58 | [{<<"app">>,<<"parse_trans">>}, |
| 59 59 | {<<"optional">>,false}, |
| 60 60 | {<<"requirement">>,<<"3.4.2">>}]}, |
| 61 | + {<<"quic">>, |
| 62 | + [{<<"app">>,<<"quic">>}, |
| 63 | + {<<"optional">>,false}, |
| 64 | + {<<"requirement">>,<<"~>2.1.2">>}]}, |
| 61 65 | {<<"ssl_verify_fun">>, |
| 62 66 | [{<<"app">>,<<"ssl_verify_fun">>}, |
| 63 67 | {<<"optional">>,false}, |
| @@ -65,5 +69,5 @@ | |
| 65 69 | {<<"webtransport">>, |
| 66 70 | [{<<"app">>,<<"webtransport">>}, |
| 67 71 | {<<"optional">>,false}, |
| 68 | - {<<"requirement">>,<<"~>0.4.5">>}]}]}. |
| 69 | - {<<"version">>,<<"4.7.4">>}. |
| 72 | + {<<"requirement">>,<<"~>0.4.8">>}]}]}. |
| 73 | + {<<"version">>,<<"4.9.1">>}. |
Loading more files…