Documentation
¶
Overview ¶
Package httpx hosts shared HTTP helpers used by extracted handler packages: the canonical sentinel-error to status mapping, the {code,message} JSON error body, the URL-param ULID parser, and the no-trust client IP shim. Extracted from root handlers.go in PR E of the 2026-06 architecture reorg so internal handler packages do not each re-implement these.
Index ¶
- func ClientIP(r *http.Request) string
- func DecodeJSON(r *http.Request, v any) error
- func ErrToHTTP(w http.ResponseWriter, err error)
- func Error(w http.ResponseWriter, status int, message string)
- func ParseULIDParam(s string) (models.ULID, error)
- func ParseULIDPath(r *http.Request, name string) (models.ULID, bool)
- func PathULID(w http.ResponseWriter, r *http.Request, name string) (models.ULID, bool)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- func WriteJSONError(w http.ResponseWriter, status int, code, message string)
- func WriteProblemJSON(w http.ResponseWriter, status int, code, detail, instance string)
- func WriteUnauthenticated(w http.ResponseWriter, code, detail string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶
ClientIP returns the connection-level remote host (port stripped), ignoring X-Forwarded-For. Matches the legacy root extractClientIP.
func DecodeJSON ¶
DecodeJSON decodes the request body into v, capping the read at 64 KiB to prevent memory DoS. Mirrors the legacy root decodeJSON.
func ErrToHTTP ¶
func ErrToHTTP(w http.ResponseWriter, err error)
ErrToHTTP maps any error a service layer returns to the canonical HTTP status the legacy root handlers emitted. Mirrors the root errToHTTP behavior verbatim so the public surface is unchanged.
func Error ¶
func Error(w http.ResponseWriter, status int, message string)
Error writes a JSON error body whose stable code derives from the HTTP status. Replaces plain-text http.Error across the handlers.
func ParseULIDParam ¶
ParseULIDParam parses a Crockford-base32 ULID from a URL path parameter. Returns an error on any malformed input; callers map that to 400.
func ParseULIDPath ¶
ParseULIDPath is the silent variant of PathULID: it does not write a response on failure, leaving the caller free to emit a structured problem+json body. Mirrors the legacy root parseULIDPath.
func PathULID ¶
PathULID parses a chi URL path parameter into a ULID. On parse failure it writes a 400 plain-text response and returns ok=false. Mirrors the legacy root pathULID exactly.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, v any)
WriteJSON marshals v as a JSON body with status. Used by every extracted handler package; identical to the legacy root writeJSON.
func WriteJSONError ¶
func WriteJSONError(w http.ResponseWriter, status int, code, message string)
WriteJSONError emits the v0.2+ {"code":...,"message":...} body.
func WriteProblemJSON ¶
func WriteProblemJSON(w http.ResponseWriter, status int, code, detail, instance string)
WriteProblemJSON emits a minimal RFC 7807 problem+json body. The admin package owns the richer variant with type URIs; this in-package helper keeps the middleware self-contained and avoids an import cycle.
func WriteUnauthenticated ¶
func WriteUnauthenticated(w http.ResponseWriter, code, detail string)
WriteUnauthenticated emits a 401 with both the RFC 7807 body and an RFC 7235 WWW-Authenticate header. Session-cookie auth is the primary scheme; consumers using bearer tokens against the OAuth AS / mcpresource surface get the Bearer challenge from those packages instead.
Types ¶
This section is empty.