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
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ UNRELEASED

### Refactor

- HTTP/2 is now delegated to the `erlang_h2` library (hex `h2` 0.3.0).
Hackney no longer ships its own HTTP/2 framing, HPACK codec, or
connection/stream state machine:
- `hackney_http2.erl`, `hackney_http2_machine.erl`, `hackney_hpack.erl`
and the `hackney_hpack_huffman*` headers have been removed.
- `hackney_conn.erl` now starts an `h2_connection` gen_statem on the
post-ALPN socket, transfers socket ownership, and translates
`{h2, Conn, Event}` owner-messages into hackney's sync replies or
`{hackney_response, Ref, _}` async events.
- Server push handling (RFC 7540 §8.2, deprecated) is no longer exposed.
The `enable_push` option is a no-op.
- Public user-facing API is unchanged: `hackney:request/5`, streaming
async responses, pooled HTTP/2 connections, and `request_async` all
behave as before.
- HTTP/3 is now delegated to the `erlang_quic` library's `quic_h3` module
(hex `quic` 1.0.0). Hackney no longer ships its own HTTP/3 framing,
QPACK codec, control-stream or unidirectional-stream handling:
Expand Down
34 changes: 14 additions & 20 deletions guides/http2_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Hackney supports HTTP/2 with automatic protocol negotiation via ALPN (Applicatio
- **Multiplexing** - Multiple requests share a single connection
- **Header compression** - HPACK compression reduces overhead
- **Flow control** - Automatic window management
- **Server push** - Optional support for server-initiated streams
- **Delegated to `erlang_h2`** - the underlying HTTP/2 stack is the `h2`
hex package; hackney exposes the same request API it always did

## Quick Start

Expand Down Expand Up @@ -243,20 +244,10 @@ end) || Path <- Paths].

## Server Push

Server push allows the server to send resources before the client requests them. By default, hackney rejects server pushes. To handle them:

```erlang
%% Using low-level API with push handler
{ok, Conn} = hackney_conn:start_link(#{
host => "example.com",
port => 443,
transport => hackney_ssl,
enable_push => self() %% Receive push notifications
}),

%% Push notifications arrive as messages:
%% {hackney_push, ConnPid, {PromisedStreamId, Method, Scheme, Authority, Path, Headers}}
```
Server push (RFC 7540 §8.2) is deprecated and no longer supported by the
underlying `h2` library. The `enable_push` option is accepted for
backwards-compatibility but is a no-op; pushes from the server are silently
refused.

## Flow Control

Expand All @@ -275,11 +266,14 @@ HTTP/2 specific errors:
case hackney:get(URL) of
{ok, Status, Headers, Body} ->
ok;
{error, {h2_connection_error, ErrorCode}} ->
%% HTTP/2 connection-level error
io:format("HTTP/2 error: ~p~n", [ErrorCode]);
{error, closed} ->
%% Connection closed (GOAWAY received)
{error, {goaway, ErrorCode}} ->
%% Peer sent GOAWAY
io:format("HTTP/2 GOAWAY: ~p~n", [ErrorCode]);
{error, {stream_error, ErrorCode}} ->
%% Peer sent RST_STREAM for this request
io:format("HTTP/2 stream reset: ~p~n", [ErrorCode]);
{error, {closed, _Reason}} ->
%% Connection closed
ok;
{error, Reason} ->
io:format("Error: ~p~n", [Reason])
Expand Down
4 changes: 3 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
{deps, [
%% Pure Erlang QUIC + HTTP/3 stack
{quic, "1.0.0"},
%% Pure Erlang HTTP/2 stack
{h2, "0.3.0"},
{idna, "~>7.1.0"},
{mimerl, "~>1.4"},
{certifi, "~>2.16.0"},
Expand Down Expand Up @@ -115,7 +117,7 @@
{exclude_mods, [hackney_metrics_prometheus]},
{base_plt_apps, [erts, stdlib, kernel, crypto, runtime_tools]},
{plt_apps, top_level_deps},
{plt_extra_apps, [quic]},
{plt_extra_apps, [quic, h2]},
{plt_location, local},
{plt_prefix, "hackney"},
{base_plt_location, "."},
Expand Down
3 changes: 2 additions & 1 deletion src/hackney.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
idna,
mimerl,
certifi,
ssl_verify_fun]},
ssl_verify_fun,
h2]},
{included_applications, []},
{mod, { hackney_app, []}},
{env, [{timeout, 150000},
Expand Down
Loading
Loading