httpcorrelation

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package httpcorrelation explicitly propagates correlation metadata over HTTP. New composes an explicit Factory with Wrap for inbound handlers and Inject for outbound hops. Middleware installation, peer authentication, transport execution, cancellation and retry remain application-owned. Configuration may be shared when the generator/Trust callback are safe to share; request/response header maps need exclusive mutation ownership. No global middleware, goroutine, body consumption or shutdown is introduced.

Deprecated: use github.com/faustbrian/go-correlation/adapters/http. This package remains supported through the documented compatibility interval.

Index

Constants

View Source
const (
	// CorrelationHeader carries the logical workflow identifier.
	CorrelationHeader = "X-Correlation-ID"
	// RequestHeader carries the current HTTP hop identifier.
	RequestHeader = "X-Request-ID"
	// CausationHeader carries the immediate parent identifier.
	CausationHeader = "X-Causation-ID"
)

Variables

View Source
var ErrInvalidOptions = errors.New("http correlation: invalid options")

ErrInvalidOptions reports invalid HTTP adapter configuration.

Functions

This section is empty.

Types

type InvalidPolicy

type InvalidPolicy uint8

InvalidPolicy controls malformed or ambiguous inbound metadata.

const (
	// ReplaceInvalid discards all metadata on extraction failure and creates a
	// fresh root. With no Trust callback, inbound parsing is skipped entirely.
	ReplaceInvalid InvalidPolicy = iota
	// RejectInvalid returns HTTP 400 before application code runs.
	RejectInvalid
)

type Middleware

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

Middleware owns explicit HTTP extraction, trust, context, and injection. Use New; immutable configuration is shareable subject to Factory/Trust safety. It owns neither request/response lifetime nor mutable header synchronization.

func New

func New(factory *correlation.Factory, options Options) (*Middleware, error)

New constructs an HTTP adapter without installing global middleware. Nil factory, unknown Invalid mode or invalid codec policy returns an error; factory and Trust are borrowed. Supply a constructed Factory, not its zero value.

func (*Middleware) Inject

func (middleware *Middleware) Inject(request *http.Request, parent correlation.Values) (correlation.Values, error)

Inject creates and injects the next outbound HTTP hop without sending it. It mutates request.Header (allocating it if nil), preserving unrelated fields and refusing populated correlation fields through Codec. Failures return zero Values but may allocate headers/consume generator state; no rollback occurs. Nil request or Middleware returns ErrInvalidOptions.

func (*Middleware) Wrap

func (middleware *Middleware) Wrap(next http.Handler) http.Handler

Wrap creates one fresh request ID per HTTP request. Valid inbound metadata is preserved only when Trust explicitly accepts the immediate peer. Extraction failure under RejectInvalid returns 400 before next; generation failure returns 500. In both successful and rejected flows, canonical request/response header keys are written; this is not removal of every alternate-cased map key. Request headers must be writable/nonnil and exclusively owned for the call. Wrap derives context but does not deep-copy the request, consume its body, cancel work or recover callback/handler panics. Nil next yields a 500 handler.

type Options

type Options struct {
	// Policy configures inbound/outbound codec validation, independently of the
	// supplied Factory's policy; zero selects correlation's defaults.
	Policy correlation.Policy
	// Invalid selects replacement (zero) or HTTP 400 for malformed metadata.
	Invalid InvalidPolicy
	// Trust is a borrowed synchronous peer-authentication decision. Nil trusts
	// no inbound IDs. It may run concurrently and can block or panic; the
	// adapter adds no recovery, deadline or authentication of its own.
	Trust func(*http.Request) bool
}

Options configure immutable HTTP propagation policy.

Directories

Path Synopsis
Package requestidbridge integrates explicitly with request ID middleware such as http-middleware/requestid without importing hidden context keys.
Package requestidbridge integrates explicitly with request ID middleware such as http-middleware/requestid without importing hidden context keys.

Jump to

Keyboard shortcuts

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