pub struct X402Middleware { /* private fields */ }server only.Expand description
Application-level x402 middleware. Owns a ResourceServer.
Not a tower::Layer. Paid routes are built with Self::with_price_tag.
Implementations§
Source§impl X402Middleware
impl X402Middleware
Sourcepub fn from_facilitator(fac: impl Facilitator + 'static) -> Self
pub fn from_facilitator(fac: impl Facilitator + 'static) -> Self
Wraps fac in a new ResourceServer.
Sourcepub const fn from_resource_server(server: ResourceServer) -> Self
pub const fn from_resource_server(server: ResourceServer) -> Self
Creates middleware that owns an existing ResourceServer.
Sourcepub fn try_new(url: &str) -> Result<Self, FacilitatorClientError>
pub fn try_new(url: &str) -> Result<Self, FacilitatorClientError>
Remote facilitator from a base URL.
§Errors
FacilitatorClientError when the URL cannot be parsed or endpoints built.
Sourcepub fn with_scheme(
self,
network: ChainIdPattern,
scheme: impl SchemeNetworkServer + 'static,
) -> Self
pub fn with_scheme( self, network: ChainIdPattern, scheme: impl SchemeNetworkServer + 'static, ) -> Self
Registers a scheme/network adapter.
Sourcepub fn with_extension(self, extension: impl Extension + 'static) -> Self
pub fn with_extension(self, extension: impl Extension + 'static) -> Self
Registers a protocol extension advertised on 402 responses.
Sourcepub fn with_base_url(&self, base_url: Url) -> Self
pub fn with_base_url(&self, base_url: Url) -> Self
Public origin used to build ResourceInfo.url. Required before with_price_tag.
Never derived from Host and never defaulted to http://localhost.
Sourcepub const fn resource_server(&self) -> &ResourceServer
pub const fn resource_server(&self) -> &ResourceServer
Owned resource server.
Sourcepub fn with_siwx(&self, gate: SiwxGate) -> Self
Available on crate feature siwx only.
pub fn with_siwx(&self, gate: SiwxGate) -> Self
siwx only.Enables SIWX on layers built from this middleware.
Empty static tags still require Self::with_auth_only before
Self::with_price_tags.
Sourcepub fn with_auth_only(&self, gate: SiwxGate) -> Self
Available on crate feature siwx only.
pub fn with_auth_only(&self, gate: SiwxGate) -> Self
siwx only.Enables SIWX and treats empty price tags as auth-only.
Call before Self::with_price_tags with an empty list. Grants access
on valid signature even without a paid-address hit.
Sourcepub fn with_price_tag(
&self,
price_tag: PriceTag,
) -> Result<X402Layer<StaticPriceTags>, BuildError>
pub fn with_price_tag( &self, price_tag: PriceTag, ) -> Result<X402Layer<StaticPriceTags>, BuildError>
Static single-tag layer. Fails when Self::with_base_url was not called.
§Errors
BuildError::MissingBaseUrl, then other BuildError variants from
static tag validation. with_resource does not waive base_url.
Static multi-tag layer.
Empty list is BuildError::EmptyPriceTags unless Self::with_auth_only
was already called.
§Errors
BuildError::MissingBaseUrl when with_base_url was not called, or
other BuildError variants when static tags are invalid.
with_resource does not waive base_url.
Sourcepub fn with_dynamic_price<F, Fut>(
&self,
callback: F,
) -> Result<X402Layer<DynamicPriceTags>, BuildError>
pub fn with_dynamic_price<F, Fut>( &self, callback: F, ) -> Result<X402Layer<DynamicPriceTags>, BuildError>
Trait Implementations§
Source§impl Clone for X402Middleware
impl Clone for X402Middleware
Source§fn clone(&self) -> X402Middleware
fn clone(&self) -> X402Middleware
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for X402Middleware
impl Debug for X402Middleware
Source§impl TryFrom<&str> for X402Middleware
impl TryFrom<&str> for X402Middleware
Auto Trait Implementations§
impl !RefUnwindSafe for X402Middleware
impl !UnwindSafe for X402Middleware
impl Freeze for X402Middleware
impl Send for X402Middleware
impl Sync for X402Middleware
impl Unpin for X402Middleware
impl UnsafeUnpin for X402Middleware
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more