client

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2026 License: MIT, Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package client provides an HTTP client with automatic 402 Payment Required handling.

Package client provides the generic HTTP 402 retry transport used by MPP payment methods.

Examples import this package by its bare name. The Tempo charge package uses the alias `charge`, so there is no conflict.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an HTTP client with automatic 402 payment handling.

func New

func New(methods []Method, opts ...Option) *Client

New creates a Client with the given payment methods.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request, handling 402 responses automatically. If a 402 is received with a WWW-Authenticate: Payment header, it finds a matching method, creates credentials, and retries.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (*http.Response, error)

Get is a convenience method for GET requests.

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, contentType string, body io.Reader) (*http.Response, error)

Post is a convenience method for POST requests.

type Method

type Method interface {
	// Name returns the method name this handler supports (e.g., "tempo").
	Name() string
	// CreateCredential creates a payment credential for the given challenge.
	CreateCredential(ctx context.Context, challenge *mpp.Challenge) (*mpp.Credential, error)
}

Method is the interface that payment methods must implement for client-side use.

type Option

type Option func(*Client)

Option configures the Client.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom http.Client.

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport is an http.RoundTripper that handles 402 Payment Required responses. It wraps an inner transport and automatically negotiates payment.

func NewTransport

func NewTransport(methods []Method, inner http.RoundTripper) *Transport

NewTransport creates a payment-aware transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper with automatic 402 handling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL