idempotencyhttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package idempotencyhttp provides buffered net/http middleware backed by an idempotency.Service. Applications must supply semantic key and canonical fingerprint policies; the package does not infer business identity from unstable transport details.

Index

Constants

View Source
const (
	// HeaderKey carries the caller's idempotency key.
	HeaderKey = "Idempotency-Key"
	// HeaderOutcome reports the semantic result of the request.
	HeaderOutcome = "Idempotency-Outcome"
	// HeaderReplayed is true when the response came from a durable record.
	HeaderReplayed = "Idempotency-Replayed"
	// MaxReplayResponseBytes is the largest handler body accepted for replay.
	MaxReplayResponseBytes = 700 * 1024
)

Variables

View Source
var ErrResponseTooLarge = errors.New("idempotencyhttp: response exceeds replay limit")

ErrResponseTooLarge is returned to a handler whose body crosses its limit.

Functions

This section is empty.

Types

type FingerprintFunc

type FingerprintFunc func(*http.Request) (idempotency.Fingerprint, error)

FingerprintFunc computes the application's canonical request fingerprint.

type KeyFunc

type KeyFunc func(*http.Request, string) (idempotency.Key, error)

KeyFunc maps a request and header value to an application-scoped key.

type Middleware

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

Middleware durably elects a handler and replays its bounded response.

func New

func New(options Options) (*Middleware, error)

New validates options and constructs middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps next with durable acquisition and response replay.

type Options

type Options struct {
	// Service owns the durable state machine.
	Service *idempotency.Service
	// Lease bounds one handler owner's authority.
	Lease time.Duration
	// MaxResponseBytes bounds the buffered handler body. Zero defaults to 64 KiB.
	MaxResponseBytes int
	// ReplayHeaders names response headers to persist and replay.
	ReplayHeaders []string
	// TransitionTimeout bounds detached panic cleanup. Zero defaults to five seconds.
	TransitionTimeout time.Duration
	// Key constructs the fully scoped semantic key.
	Key KeyFunc
	// Fingerprint supplies canonical business-request identity.
	Fingerprint FingerprintFunc
}

Options configures durable HTTP handler ownership and replay.

Jump to

Keyboard shortcuts

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