proxy

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoverMiddleware

func RecoverMiddleware(next http.Handler) http.Handler

RecoverMiddleware catches unexpected panics from downstream handlers.

CRITICAL re-panic rule: if the recovered value is http.ErrAbortHandler the panic is re-raised immediately so net/http's streaming-abort machinery can handle it. Swallowing it would break mid-stream delivery.

For every other non-nil panic value the middleware:

  1. Calls metrics.Panic() to increment the counter.
  2. Logs method, path, X-Request-ID, panic value, and stack trace.
  3. Writes HTTP 500 JSON when no response bytes have been sent yet.
  4. Otherwise (the response already started) re-raises http.ErrAbortHandler so the client sees an aborted connection rather than a body that silently stops and looks complete.

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders sets baseline security response headers on every request. Applied to both the proxy and admin HTTP servers in main.go, since they're two independent http.Server instances with no other shared middleware point besides RecoverMiddleware.

Types

type AccessLogEntry

type AccessLogEntry struct {
	RequestID  string `json:"request_id"`
	KeyName    string `json:"key_name"`
	Model      string `json:"model"`
	Node       string `json:"node"`
	Status     int    `json:"status"`
	LatencyMs  int64  `json:"latency_ms"`
	Cloud      bool   `json:"cloud"`
	TimeUnixMs int64  `json:"ts"`
}

AccessLogEntry holds the per-request fields written to the access log.

type AccessLogger

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

AccessLogger writes one JSON line per request to an underlying io.Writer. It is safe for concurrent use.

func NewAccessLogger

func NewAccessLogger(w io.Writer, enabled bool) *AccessLogger

NewAccessLogger returns an AccessLogger that writes to w when enabled is true. Pass enabled=false to create a no-op logger (w may be nil in that case).

func (*AccessLogger) Log

func (a *AccessLogger) Log(e AccessLogEntry)

Log serialises e as a single JSON line followed by '\n' and writes it atomically under the mutex. If the logger is disabled or w is nil the call is a no-op. Write errors are silently swallowed - access logging must never break request handling.

type Handler

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

func NewHandler

func NewHandler(r *router.Router, a *admin.Server, al *audit.Logger) *Handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Handler) SetAccessLogger

func (h *Handler) SetAccessLogger(l *AccessLogger)

SetAccessLogger installs the structured access logger. Passing nil keeps the existing no-op logger so callers never have to nil-check.

func (*Handler) SetAllowManagementEndpoints

func (h *Handler) SetAllowManagementEndpoints(allow bool)

SetAllowManagementEndpoints toggles the management-endpoint guard. Pass true only for single-tenant deployments where the caller is trusted to manage models on backend nodes. Default (false) blocks them.

func (*Handler) SetAuth

func (h *Handler) SetAuth(m *auth.Middleware)

SetAuth wires the auth middleware so the proxy can refund a key's rate-limit and quota budget when a request is rejected by policy (model allow-list) before ever reaching a node. Optional; nil keeps refunds disabled.

func (*Handler) SetTrustProxyHeaders

func (h *Handler) SetTrustProxyHeaders(trust bool)

SetTrustProxyHeaders toggles whether X-Forwarded-For/X-Real-IP are trusted for the admin request log's client IP. Pass true only when marbor sits behind a trusted reverse proxy/load balancer that sets these headers itself and is the sole path to the proxy port; otherwise a direct client can forge them. Default false logs r.RemoteAddr (the real TCP peer) instead.

Jump to

Keyboard shortcuts

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