hackney_keepalive (hackney v4.4.5)

View Source

HTTP/1.x keepalive semantics.

Single source of truth for deciding whether an HTTP/1.x connection must be closed (not reused) after a response, per RFC 7230. The Connection header is a list-valued, hop-by-hop field (RFC 7230 3.2.2, 6.1): a recipient may get it as several header lines or as one comma-joined value, and both are equivalent. It is forbidden in HTTP/2 and HTTP/3, so these rules apply only to HTTP/1.x; multiplexed conns are never pooled in available.

Every function tolerates undefined or malformed header objects so a bad header can never crash the keepalive decision.

Summary

Functions

Lower-cased, trimmed tokens from every Connection header.

Whether request headers carry Connection: close.

Whether a parsed HTTP/1.x response means the connection must close.

Functions

connection_tokens(Headers)

-spec connection_tokens(term()) -> [binary()].

Lower-cased, trimmed tokens from every Connection header.

Defensive at each layer: an undefined or malformed header object yields [], and a value that does not convert to a binary is skipped rather than crashing.

request_closes(ReqHeaders)

-spec request_closes(term()) -> boolean().

Whether request headers carry Connection: close.

should_close(Version, RespHeaders, RequestClose)

-spec should_close(Version, RespHeaders, RequestClose) -> boolean()
                      when
                          Version :: {integer(), integer()} | undefined,
                          RespHeaders :: term(),
                          RequestClose :: boolean().

Whether a parsed HTTP/1.x response means the connection must close.

The caller (hackney_conn:should_close_connection/1) guards the "no response observed yet" case; here Version/RespHeaders describe a response that was actually parsed. Order matters: an explicit close wins over version default.