httpserver

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationFunc

func AuthenticationFunc(auth UserAuthenticator, apiKeyAuthenticator APIKeyAuthenticator) func(context.Context, *openapi3filter.AuthenticationInput) error

AuthenticationFunc is called by the OapiRequestValidator to verify security schemes

func ClientIPFromRealIPMiddleware

func ClientIPFromRealIPMiddleware(trustedProxy netip.Addr, logger *slog.Logger) func(http.Handler) http.Handler

ClientIPFromRealIPMiddleware extracts client IP from X-Real-IP only when the direct peer address is within trustedProxy.

If the peer is not trusted, X-Real-IP is ignored to prevent spoofing and a security warning is logged when that header is present.

func ClientIPFromRequestMiddleware

func ClientIPFromRequestMiddleware() func(http.Handler) http.Handler

ClientIPFromRequestMiddleware is middleware that extracts the client IP from r.RemoteAddr and sets it in the request context. It ignores any X-Forwarded-For headers.

func DevicePairingRateLimitMiddleware added in v0.4.0

func DevicePairingRateLimitMiddleware(requests int, window time.Duration, logger *slog.Logger) func(http.Handler) http.Handler

DevicePairingRateLimitMiddleware rate limits POST /api/v1/device-pair by client IP. When the limit fires a WARN is emitted with the client IP and path so scanning is visible in container logs.

func HeartbeatRateLimitMiddleware

func HeartbeatRateLimitMiddleware(requests int, window time.Duration, logger *slog.Logger) func(http.Handler) http.Handler

HeartbeatRateLimitMiddleware rate limits POST /api/v1/heartbeat by client IP. When the limit fires a WARN is emitted with the client IP and path so scanning is visible in container logs.

func LoginRateLimitMiddleware

func LoginRateLimitMiddleware(requests int, window time.Duration, logger *slog.Logger) func(http.Handler) http.Handler

LoginRateLimitMiddleware rate limits POST /api/v1/auth/login by client IP. When the limit fires a WARN is emitted with the client IP and path so brute-force attempts are visible in container logs.

func MaxBodySizeMiddleware

func MaxBodySizeMiddleware(maxBytes int64) func(http.Handler) http.Handler

MaxBodySizeMiddleware limits request body size to prevent large payloads from exhausting memory.

func NewServer

func NewServer(
	deviceHandler *DeviceHandler,
	authHandler *AuthHandler,
	ruleHandler *RuleHandler,
	queriesHandler *QueriesHandler,
	policyHandler *PolicyHandler,
	rollupHandler *RollupHandler,
	pairingHandler *DevicePairingHandler,
	hostsHandler *HostsHandler,
	userAccessHandler *UserAccessHandler,
	networkPoliciesHandler *NetworkPoliciesHandler,
	logger *slog.Logger,
	trustedProxy netip.Addr,
) http.Handler

func RequestLoggerMiddleware

func RequestLoggerMiddleware(_ *slog.Logger) func(http.Handler) http.Handler

RequestLoggerMiddleware stores the request ID in context so the custom slog.Handler can stamp it on every log record produced during this request. The base logger is no longer stored in context; each handler uses its own struct-level logger.

func StartAndWait

func StartAndWait(ctx context.Context, handler http.Handler, cfg ServerConfig, logger *slog.Logger) error

StartAndWait starts the HTTP server in the background. It blocks until a server error occurs or the provided context is cancelled, at which point it performs a graceful shutdown with the configured timeout.

func StartPprofServer added in v0.4.0

func StartPprofServer(_ context.Context, _ *slog.Logger) error

StartPprofServer is a no-op in the default build: the pprof debug server is compiled in only under the `pprof` build tag (see pprof_on.go). The handlers are physically absent from any binary built without the tag, so there is nothing to misconfigure or enable in a real deployment.

Types

type APIKeyAuthenticator

type APIKeyAuthenticator = device.APIKeyAuthenticator

type AuthHandler

type AuthHandler = auth.HTTPHandler

type DeviceHandler

type DeviceHandler = device.HTTPHandler

type DevicePairingHandler added in v0.4.0

type DevicePairingHandler = devicepairing.HTTPHandler

type HostsHandler added in v0.4.0

type HostsHandler = hosts.HTTPHandler

type NetworkPoliciesHandler added in v0.4.0

type NetworkPoliciesHandler = networkpolicies.HTTPHandler

type PolicyHandler

type PolicyHandler = policy.HTTPHandler

type QueriesHandler

type QueriesHandler = queries.HTTPHandler

type RollupHandler added in v0.4.0

type RollupHandler = rollup.HTTPHandler

type RuleHandler

type RuleHandler = rule.HTTPHandler

type ServerConfig

type ServerConfig struct {
	Port              int
	ReadTimeout       time.Duration
	ReadHeaderTimeout time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	MaxHeaderBytes    int
	ShutdownTimeout   time.Duration
}

ServerConfig holds configuration for the HTTP server lifecycle.

func DefaultServerConfig

func DefaultServerConfig() ServerConfig

func DefaultServerConfigFromConf

func DefaultServerConfigFromConf(port int) ServerConfig

type UserAccessHandler added in v0.4.0

type UserAccessHandler = useraccess.HTTPHandler

type UserAuthenticator

type UserAuthenticator = auth.UserAuthenticator

Jump to

Keyboard shortcuts

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