http

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHeaderKey = sdk.DefaultHeaderKey

DefaultHeaderKey is used by the middleware to extract the X-Diverge-Env header and inject it into the request context.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) string

FromContext extracts the environment name from the context.

func PropagateEnvironment

func PropagateEnvironment(next http.Handler) http.Handler

PropagateEnvironment returns middleware that propagates the x-diverge-env header from incoming requests to outgoing requests via the request context.

Example:

// Incoming handler:
mux.Use(divergehttp.PropagateEnvironment)

// Outgoing client:
client := &http.Client{
    Transport: divergehttp.RoundTripper(http.DefaultTransport),
}

func PropagateEnvironmentWithOptions added in v0.7.0

func PropagateEnvironmentWithOptions(opts ...Option) func(http.Handler) http.Handler

PropagateEnvironmentWithOptions returns middleware with configurable extraction sources for the preview environment identifier.

Precedence: Header → Query Parameter → Subdomain (first match wins).

Example:

mux.Use(divergehttp.PropagateEnvironmentWithOptions(
    divergehttp.WithBaseDomain("preview.example.com"),
    divergehttp.WithQueryParams("x-diverge-env", "diverge_env"),
))

func RoundTripper

func RoundTripper(base http.RoundTripper) http.RoundTripper

RoundTripper wraps an http.RoundTripper to inject x-diverge-env from context into outgoing HTTP requests.

Types

type Option added in v0.7.0

type Option func(*middlewareConfig)

Option configures the middleware behavior.

func WithBaseDomain added in v0.7.0

func WithBaseDomain(domain string) Option

WithBaseDomain configures subdomain-based environment extraction. For example, WithBaseDomain("preview.example.com") extracts "pr-123" from requests to "pr-123.preview.example.com".

func WithQueryParams added in v0.7.0

func WithQueryParams(keys ...string) Option

WithQueryParams configures query parameter keys to extract the environment from. For example, WithQueryParams("x-diverge-env", "diverge_env") checks both keys.

func WithStripQueryParam added in v0.7.0

func WithStripQueryParam(strip bool) Option

WithStripQueryParam removes the matched query parameter from the URL after extraction. The request is cloned before mutation to prevent data races.

WARNING: Do not use with webhook handlers that verify HMAC signatures against the full URL — stripping parameters invalidates the signature.

Jump to

Keyboard shortcuts

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