httpx

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 9 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP returns the connection-level remote host (port stripped), ignoring X-Forwarded-For. Matches the legacy root extractClientIP.

func DecodeJSON

func DecodeJSON(r *http.Request, v any) error

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

func ParseULIDParam(s string) (models.ULID, error)

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

func ParseULIDPath(r *http.Request, name string) (models.ULID, bool)

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

func PathULID(w http.ResponseWriter, r *http.Request, name string) (models.ULID, bool)

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.

Jump to

Keyboard shortcuts

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