httphelpers

package
v0.1.147 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: GPL-2.0, GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httphelpers provides shared HTTP handler prelude helpers used across server sub-packages. This breaks the import cycle between server/ and its sub-packages (queryhandlers, confighandlers, etc.) that previously required copy-pasting these helpers.

The method gate and body decoder delegate to the webhttp prelude primitives (RequireMethod, LimitBody, MaxJSONBody) so subflux inherits the RFC-9110 Allow header on 405s and the MaxBytesReader overflow-to-400 behavior, while keeping subflux's own error-code taxonomy for the response envelope.

Index

Constants

View Source
const MaxDefaultBodySize = webhttp.MaxJSONBody

MaxDefaultBodySize is the default JSON body size cap for most handlers (1 MiB), aliased to webhttp.MaxJSONBody so the limit has a single definition.

Variables

This section is empty.

Functions

func DecodeJSONBody

func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst any, maxBytes int64) bool

DecodeJSONBody decodes a JSON request body into dst under a size cap, via webhttp.DecodeJSONInto (http.MaxBytesReader cap + single-value decode + trailing-data rejection): a body exceeding maxBytes, malformed JSON, or data after the first value fails the decode rather than being silently accepted. A maxBytes of 0 or less uses MaxDefaultBodySize. Writes subflux's 400 envelope (code "bad_request") and returns false on any decode failure.

func RequireGET

func RequireGET(w http.ResponseWriter, r *http.Request) bool

RequireGET is sugar for RequireMethod(w, r, http.MethodGet).

func RequireMethod

func RequireMethod(w http.ResponseWriter, r *http.Request, method string) bool

RequireMethod checks that the request method matches the expected value. On a mismatch it delegates to webhttp.RequireMethod, which sets the RFC-9110 Allow header to the permitted method and writes subflux's {error,code,request_id} 405 envelope (code "method_not_allowed"), then returns false.

func RequirePOST

func RequirePOST(w http.ResponseWriter, r *http.Request) bool

RequirePOST is sugar for RequireMethod(w, r, http.MethodPost).

Types

This section is empty.

Jump to

Keyboard shortcuts

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