internal

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const JA4HHeaderName = "X-Http-Fingerprint-Ja4h"

JA4HHeaderName is the name of the HTTP header that the JA4H middleware adds to requests, holding the request's JA4H fingerprint. It is also used to detect whether a policy references the fingerprint, so that the relatively expensive computation can be skipped when no rule needs it.

Variables

View Source
var (
	ErrCantSplitHostParse = errors.New("internal: unable to net.SplitHostParse")
	ErrCantParseRemoteIP  = errors.New("internal: unable to parse remote IP")
)
View Source
var CGNat = netip.MustParsePrefix("100.64.0.0/10")
View Source
var HealthSrv = health.NewServer()

Functions

func BasicAuth added in v1.26.0

func BasicAuth(realm, username, password string, next http.Handler) http.Handler

BasicAuth wraps next in HTTP Basic authentication using the provided credentials. If either username or password is empty, next is returned unchanged and a debug log line is emitted.

Credentials are compared in constant time to avoid leaking information through timing side channels.

func ClampIP added in v1.24.0

func ClampIP(addr netip.Addr) (netip.Prefix, bool)

func CustomRealIPHeader added in v1.23.0

func CustomRealIPHeader(customRealIPHeaderValue string, next http.Handler) http.Handler

CustomXRealIPHeader sets the X-Real-IP header to the value of a different header. Used in environments where the upstream proxy sets the request's origin IP in a custom header.

func FastHash added in v1.20.0

func FastHash(text string) string

FastHash is a high-performance non-cryptographic hash function suitable for internal caching, policy rule identification, and other performance-critical use cases where cryptographic security is not required.

func GetFilteredHTTPLogger added in v1.18.0

func GetFilteredHTTPLogger() *log.Logger

func GetHealth added in v1.21.0

func GetRequestLogger added in v1.17.0

func GetRequestLogger(base *slog.Logger, r *http.Request) *slog.Logger

func GzipMiddleware added in v1.19.0

func GzipMiddleware(level int, next http.Handler) http.Handler

func InitSlog

func InitSlog(level string, sink io.Writer) *slog.Logger

func JA4H added in v1.21.0

func JA4H(next http.Handler) http.Handler

func NoBrowsing added in v1.16.0

func NoBrowsing(next http.Handler) http.Handler

NoBrowsing prevents directory browsing by returning a 404 for any request that ends with a "/".

func NoStoreCache added in v1.16.0

func NoStoreCache(next http.Handler) http.Handler

NoStoreCache sets the Cache-Control header to no-store for the response.

func RealIP added in v1.24.0

func RealIP(r *http.Request) (netip.Addr, bool)

func RemoteXRealIP added in v1.16.0

func RemoteXRealIP(useRemoteAddress bool, bindNetwork string, next http.Handler) http.Handler

RemoteXRealIP sets the X-Real-Ip header to the request's real IP if the setting is enabled by the user.

func SHA256sum added in v1.15.0

func SHA256sum(text string) string

SHA256sum computes a cryptographic hash. Still used for proof-of-work challenges where we need the security properties of a cryptographic hash function.

func SetHealth added in v1.21.0

func SetHealth(svc string, status healthv1.HealthCheckResponse_ServingStatus)

func SetupListener added in v1.26.0

func SetupListener(network, address, socketMode string) (net.Listener, string, error)

SetupListener sets up a network listener based on the input from configuration envvars. It returns a network listener and the URL to that listener or an error.

func UnbreakDocker added in v1.21.0

func UnbreakDocker()

func UnchangingCache

func UnchangingCache(next http.Handler) http.Handler

UnchangingCache sets the Cache-Control header to cache a response for 1 year if and only if the application is compiled in "release" mode by Docker.

func XForwardedForToXRealIP added in v1.14.1

func XForwardedForToXRealIP(next http.Handler) http.Handler

XForwardedForToXRealIP sets the X-Real-Ip header based on the contents of the X-Forwarded-For header.

func XForwardedForUpdate added in v1.17.0

func XForwardedForUpdate(stripPrivate bool, next http.Handler) http.Handler

XForwardedForUpdate sets or updates the X-Forwarded-For header, adding the known remote address to an existing chain if present

Types

type ErrorLogFilter added in v1.18.0

type ErrorLogFilter struct {
	Unwrap *log.Logger
}

ErrorLogFilter is used to suppress "context canceled" logs from the http server when a request is canceled (e.g., when a client disconnects).

func (*ErrorLogFilter) Write added in v1.18.0

func (elf *ErrorLogFilter) Write(p []byte) (n int, err error)

type ListOr added in v1.24.0

type ListOr[T any] []T

ListOr[T any] is a slice that can contain either a single T or multiple T values. During JSON unmarshaling, it checks if the first character is '[' to determine whether to treat the JSON as an array or a single value.

func (*ListOr[T]) UnmarshalJSON added in v1.24.0

func (lo *ListOr[T]) UnmarshalJSON(data []byte) error

type XFFComputePreferences added in v1.17.0

type XFFComputePreferences struct {
	StripPrivate  bool
	StripLoopback bool
	StripCGNAT    bool
	StripLLU      bool
	Flatten       bool
}

TODO: move into config

Directories

Path Synopsis
Package actorify lets you transform a parallel operation into a serialized operation via the Actor pattern[1].
Package actorify lets you transform a parallel operation into a serialized operation via the Actor pattern[1].
naive
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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