Skip to main content

r402_http/
lib.rs

1//! HTTP transport layer for the x402 payment protocol.
2//!
3//! # Feature Flags
4//!
5//! - `client` — reqwest-middleware buyer: 402 → `Payment-Signature` retry
6//! - `server` — Axum layer; `authorization` `SettlementMode` (Sequential / Concurrent / Background)
7
8#![cfg_attr(docsrs, feature(doc_cfg))]
9#![cfg_attr(
10    test,
11    allow(
12        clippy::indexing_slicing,
13        clippy::panic,
14        reason = "unit tests panic on assertion failure"
15    )
16)]
17
18#[cfg(any(feature = "client", feature = "server"))]
19pub mod headers;
20
21#[cfg(feature = "client")]
22#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
23pub mod buyer;
24
25#[cfg(feature = "server")]
26#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
27pub mod server;
28
29#[cfg(feature = "client")]
30#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
31pub use buyer::{WithPayments, X402Client, parse_payment_required, payment_signature_headers};
32#[cfg(any(feature = "client", feature = "server"))]
33pub use headers::{
34    EXTENSION_RESPONSES, PAYMENT_REQUIRED, PAYMENT_RESPONSE, PAYMENT_SIGNATURE, SIGN_IN_WITH_X,
35    X402_ALLOW_HEADERS, X402_EXPOSED_HEADERS, ensure_expose_headers, merge_private, set_no_store,
36};
37#[cfg(feature = "server")]
38#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
39pub use server::{SettlementMode, X402Middleware};
40
41#[cfg(test)]
42mod _dev_deps {
43    use alloy_network as _;
44    use alloy_primitives as _;
45    use alloy_provider as _;
46    use alloy_signer as _;
47    use alloy_signer_local as _;
48    use axum as _;
49    #[cfg(not(feature = "server"))]
50    use axum_core as _;
51    #[cfg(not(feature = "server"))]
52    use compact_str as _;
53    #[cfg(not(any(feature = "client", feature = "server")))]
54    use http as _;
55    use http_body_util as _;
56    #[cfg(not(feature = "client"))]
57    use r402_client as _;
58    use r402_evm as _;
59    #[cfg(not(any(feature = "siwx", feature = "server")))]
60    use r402_extensions as _;
61    #[cfg(not(feature = "server"))]
62    use r402_facilitator as _;
63    #[cfg(not(any(feature = "client", feature = "server")))]
64    use r402_protocol as _;
65    #[cfg(not(feature = "server"))]
66    use r402_server as _;
67    #[cfg(not(feature = "client"))]
68    use reqwest as _;
69    #[cfg(not(feature = "client"))]
70    use reqwest_middleware as _;
71    #[cfg(not(any(feature = "client", feature = "server")))]
72    use serde_json as _;
73    use tokio as _;
74    #[cfg(not(feature = "server"))]
75    use tower as _;
76    #[cfg(not(feature = "server"))]
77    use url as _;
78    use wiremock as _;
79}
80
81#[cfg(test)]
82mod tests {
83    #[test]
84    fn crate_loads() {
85        assert_eq!(
86            env!("CARGO_PKG_NAME"),
87            "r402-http",
88            "package name must match the crate directory"
89        );
90    }
91}