serverhttp

package
v0.1.0-rc.46 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: BSD-3-Clause Imports: 14 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 serverhttp owns shared server HTTP mechanics: bounded JSON requests, problem responses, control cookies, and private cluster bearer authentication. control, ingress, and relay API adapters use it. it owns no saved application service, database state, publisher identity, or authorization decision.

Index

Constants

View Source
const MaximumRequestBytes = 64 << 10

Variables

This section is empty.

Functions

func AuthenticateClusterRequest

func AuthenticateClusterRequest(response http.ResponseWriter, request *http.Request, secrets BearerSecrets) bool

AuthenticateClusterRequest applies the private API's cache and authentication policy before dispatching a request to a role-specific router.

func ControlCookie

func ControlCookie(origin string, cookie http.Cookie) *http.Cookie

func ControlCookieName

func ControlCookieName(origin, name string) string

ControlCookieName keeps production host-prefix guarantees separate from local HTTP.

func DecodeJSON

func DecodeJSON(response http.ResponseWriter, request *http.Request, destination any) bool

func DecodeJSONLimited

func DecodeJSONLimited(response http.ResponseWriter, request *http.Request, destination any, limit int64) bool

func Nonnegative

func Nonnegative(value int64) (uint64, bool)

func Positive

func Positive(value int64) (uint64, bool)

func ValidIdentifiers

func ValidIdentifiers(values ...string) bool

func WriteError

func WriteError(
	response http.ResponseWriter,
	request *http.Request,
	err error,
	report func(error),
	detail string,
) bool

WriteError handles the shared private API error boundary. callers supply only the role-specific detail for unexpected failures.

func WriteJSON

func WriteJSON(response http.ResponseWriter, status int, value any)

func WriteProblem

func WriteProblem(response http.ResponseWriter, status int, problemType, detail, caseID string)

func WriteProblemError

func WriteProblemError(response http.ResponseWriter, problem *ProblemError)

Types

type BearerSecrets

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

BearerSecrets authenticates a current service secret and an optional previous secret retained only for a rolling rotation.

func NewBearerSecrets

func NewBearerSecrets(current, previous string) (BearerSecrets, error)

func (BearerSecrets) Authenticate

func (s BearerSecrets) Authenticate(header http.Header) bool

func (BearerSecrets) Matches

func (s BearerSecrets) Matches(candidate string) bool

func (BearerSecrets) Valid

func (s BearerSecrets) Valid() bool

type CredentialCORSHeaders

type CredentialCORSHeaders struct {
	Request  []string
	Response []string
}

CredentialCORSHeaders lists the headers needed by one explicitly authenticated operation. cookies and other ambient browser credentials must not authorize it.

type CredentialCORSRouter

type CredentialCORSRouter struct {
	*http.ServeMux
	// contains filtered or unexported fields
}

CredentialCORSRouter adds uncredentialed CORS to an exact set of method/path patterns. it wraps generated handlers before parameter decoding and handles preflight without entering them. register all routes before serving requests.

the wildcard origin deliberately does not support credentials: "include". callers must use explicit bearer tokens or authenticated request bodies, never cookie authentication, and retain all authorization in the ordinary handlers.

func NewCredentialCORSRouter

func NewCredentialCORSRouter(mux *http.ServeMux, routes map[string]CredentialCORSHeaders) *CredentialCORSRouter

func (*CredentialCORSRouter) HandleFunc

func (router *CredentialCORSRouter) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

type ProblemError

type ProblemError struct {
	Status    int
	Type      string
	Title     string
	Code      string
	Detail    string
	RequestID string
	CaseID    string
}

ProblemError describes a service API failure without HTTP client or server details.

func NewProblemError

func NewProblemError(status int, problemType, detail string) *ProblemError

func (*ProblemError) Error

func (e *ProblemError) Error() string

Jump to

Keyboard shortcuts

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