Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Features

The crate declares Rust 1.96.0 as its compiler compatibility baseline. Default features enable the complete common extraction API: api-key, authority, authorization, client-ip, client-ip-headers, content-type, forwarded, request-id, and x-forwarded.

Every extraction feature owns one field family. Header functions contain the parsing implementation; matching Request functions delegate through request.headers(). All public APIs are exposed from the crate root.

Feature and API reference

Cargo featureAddsMain APIsSuccess value
api-keyX-API-Key, then Api-Key extractionextract_header_api_key, extract_request_api_keyOption<&str>
authorityURI authority and strict Host extractionextract_header_authority, extract_request_authorityOption<Authority>
authorizationRaw Authorization and Bearer/Basic scheme routingextract_*_authorization, extract_*_bearer_token, extract_*_basic_credentialsOption<&str>
axumOptional Axum ConnectInfo<SocketAddr> peer adapterextract_axum_socket_address, extract_axum_socket_ipOption<SocketAddr> or Option<IpAddr>
client-ipSocket-peer helpers and default/custom Header selectionextract_socket_ip, extract_client_ip, extract_client_ip_with_headers, extract_proxy_client_ipOption<IpAddr>
client-ip-headersCommon provider and proxy client-IP fieldsone extract_header_* and extract_request_* pair per fieldOption<IpAddr>
content-typeStrict Content-Type parsing and the optional mime dependencyextract_header_content_type, extract_request_content_typeOption<Mime>
forwardedStrict RFC 7239 Forwarded for= IP chainsextract_header_forwarded_for, extract_request_forwarded_forOption<Vec<IpAddr>>
request-idX-Request-Id, then Request-Id precedenceextract_header_request_id, extract_request_request_idOption<&str>
x-forwardedRaw X-Forwarded-For and X-Forwarded-Proto parsingextract_*_x_forwarded_for, extract_*_x_forwarded_protoOption<Vec<IpAddr>> or Option<Vec<String>>

The crate-wide Error and generic header utilities remain available with no default features. header includes the strict singular-field helpers and append_header_value, which appends without replacing existing field lines.

Client IP composition

extract_request_socket_address and extract_request_socket_ip read a SocketAddr stored directly in request extensions. extract_socket_ip prefers Axum ConnectInfo<SocketAddr> when the axum feature is enabled, then falls back to the direct extension. None of these peer helpers inspect Headers.

extract_client_ip uses the documented default Header order, while extract_client_ip_with_headers accepts an explicit ordered slice of ClientIpHeader values. Both return raw, untrusted Header assertions. extract_proxy_client_ip applies the default Header order and uses extract_socket_ip only when every Header in CLIENT_IP_HEADERS is absent.

The non-default axum feature enables client-ip. Its extract_axum_socket_address and extract_axum_socket_ip functions return None when ConnectInfo<SocketAddr> is absent; they never fabricate a peer.

See the client IP trust boundary before using a Header-derived address for authorization, rate limiting, or auditing.

Feature relationships

client-ip enables client-ip-headers, forwarded, and x-forwarded because its selectors use those parsing APIs. content-type enables the optional mime dependency. The normal default dependency tree does not include Axum, Tower, Tokio, tracing, or OpenTelemetry.

Enable the optional Axum adapter and runnable example explicitly:

cargo run --example axum-demo --features axum

Useful checks for consumers and contributors:

cargo check --no-default-features
cargo test --no-default-features --features authority,content-type,request-id
cargo test --no-default-features --features client-ip
cargo test --no-default-features --features client-ip-headers

This feature layout does not imply additional runtime compatibility. See Standards and compatibility for the protocol support boundary.