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
- func AuthenticateClusterRequest(response http.ResponseWriter, request *http.Request, secrets BearerSecrets) bool
- func ControlCookie(origin string, cookie http.Cookie) *http.Cookie
- func ControlCookieName(origin, name string) string
- func DecodeJSON(response http.ResponseWriter, request *http.Request, destination any) bool
- func Nonnegative(value int64) (uint64, bool)
- func Positive(value int64) (uint64, bool)
- func ValidIdentifiers(values ...string) bool
- func WriteError(response http.ResponseWriter, request *http.Request, err error, ...) bool
- func WriteJSON(response http.ResponseWriter, status int, value any)
- func WriteProblem(response http.ResponseWriter, status int, problemType, detail, caseID string)
- func WriteProblemError(response http.ResponseWriter, problem *ProblemError)
- type BearerSecrets
- type CredentialCORSHeaders
- type CredentialCORSRouter
- type ProblemError
Constants ¶
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 ControlCookieName ¶
ControlCookieName keeps production host-prefix guarantees separate from local HTTP.
func DecodeJSON ¶
func Nonnegative ¶
func ValidIdentifiers ¶
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 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 ¶
CredentialCORSHeaders lists the headers needed by one explicitly authenticated operation. cookies and other ambient browser credentials must not authorize it.
type CredentialCORSRouter ¶
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