HTTP implementation of MPP.Client.Transport over Req.
Operates on Req.Response / Req.Request structs — this module does not
construct Req clients itself. Callers (e.g. the payment-aware Req plugin)
feed responses in and receive modified requests out.
Wire format
- Payment-required response: HTTP status
402 - Challenges: one or more
WWW-Authenticateheaders carrying thePaymentscheme. Multiple challenges may appear as repeated header values or as a single comma-separated header value; both forms are handled. - Credential attachment:
Authorization: Payment <base64url-json>, produced viaMPP.Headers.format_credential/1.
API Functions
| Function | Arity | Description | Param Kinds |
|---|---|---|---|
set_credential | 2 | Attach a credential to a Req.Request as Authorization: Payment <...>. | request: value, credential: value |
get_challenges | 1 | Parse the Payment challenges from a 402 response's WWW-Authenticate headers. | response: value |
payment_required? | 1 | Return true if the HTTP response is a 402 Payment Required. | response: value |
Summary
Functions
Parse the Payment challenges from a 402 response's WWW-Authenticate headers.
Return true if the HTTP response is a 402 Payment Required.
Attach a credential to a Req.Request as Authorization: Payment <...>.
Functions
@spec get_challenges(Req.Response.t()) :: {:ok, [MPP.Challenge.t()]} | {:error, term()}
Parse the Payment challenges from a 402 response's WWW-Authenticate headers.
Parameters
response- Req.Response struct (value)
Returns
{:ok, [challenge]} on success, {:error, reason} otherwise (tagged_tuple)
Errors
:no_payment_challenges:missing_www_authenticate:invalid_scheme:missing_required_params:duplicate_param:invalid_auth_params
# descripex:contract
%{
params: %{response: %{description: "Req.Response struct", kind: :value}},
errors: [:no_payment_challenges, :missing_www_authenticate, :invalid_scheme,
:missing_required_params, :duplicate_param, :invalid_auth_params],
returns: %{
type: :tagged_tuple,
description: "`{:ok, [challenge]}` on success, `{:error, reason}` otherwise"
}
}
@spec payment_required?(Req.Response.t()) :: boolean()
@spec payment_required?(Req.Response.t()) :: false
Return true if the HTTP response is a 402 Payment Required.
Parameters
response- Req.Response struct (value)
Returns
true if status is 402 (boolean)
# descripex:contract
%{
params: %{response: %{description: "Req.Response struct", kind: :value}},
returns: %{type: :boolean, description: "true if status is 402"}
}
@spec set_credential(Req.Request.t(), MPP.Credential.t()) :: Req.Request.t()
Attach a credential to a Req.Request as Authorization: Payment <...>.
Parameters
request- Req.Request struct (value)credential- MPP.Credential struct (value)
Returns
Req.Request with the Authorization header set (struct)
# descripex:contract
%{
params: %{
request: %{description: "Req.Request struct", kind: :value},
credential: %{description: "MPP.Credential struct", kind: :value}
},
returns: %{
type: :struct,
description: "Req.Request with the Authorization header set"
}
}