middleware

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 10 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

Overview

Package middleware holds HTTP middleware; handlers live in package handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Admin

func Admin(log zerolog.Logger) func(http.Handler) http.Handler

Admin lets a request through only with an admin session or token (spec 10: the only role is admin).

func Authenticate

func Authenticate(a Authenticator, log zerolog.Logger, next http.Handler) http.Handler

Authenticate attaches the principal of a valid session cookie or API token to the request. A bad token is answered with 401; a stale cookie is ignored (anonymous). The WebSocket upgrade may carry the token as ?token= (spec 9.3).

func CSRF

func CSRF(log zerolog.Logger, next http.Handler) http.Handler

CSRF rejects state-changing requests whose Origin (or Referer) is not this host (spec 10). Requests without either are only allowed with a bearer token, which a browser never adds on its own.

func Headers

func Headers(next http.Handler) http.Handler

Headers sets the security headers of spec 10 on every response.

func Proxy

func Proxy(trusted []netip.Prefix, next http.Handler) http.Handler

Proxy resolves the client IP and HTTPS from the connection, trusting X-Forwarded-For and X-Forwarded-Proto only from the configured proxies (app.trusted_proxies).

func Read

func Read(public bool, log zerolog.Logger) func(http.Handler) http.Handler

Read lets a request through when public reading is on or a principal is attached.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, token string) (auth.Principal, error)
	AuthenticateToken(ctx context.Context, token string) (auth.Principal, error)
}

Authenticator resolves session cookies and API tokens.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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