apihttp

package
v0.7.21 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package apihttp holds HTTP helpers shared by every version of the public API (pkg/api/v1, ...). It is intentionally a leaf package with no dependencies on pkg/api so version subpackages can import it without creating an import cycle through the top-level router.

Index

Constants

View Source
const MaxJSONBodyBytes = 1 << 20 // 1 MiB

MaxJSONBodyBytes caps JSON request bodies decoded via DecodeJSON. Control requests are small (a create payload with env vars is well under 64 KiB); the cap exists so an authed caller can't balloon daemon memory with a multi-GiB body. Bulk payloads (file uploads, build contexts) stream through dedicated handlers and don't go through DecodeJSON.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) error

DecodeJSON decodes a JSON request body into dst with the body capped at MaxJSONBodyBytes. All versioned handlers must use this instead of json.NewDecoder(r.Body) directly so the size cap is uniform across v1 and the facades. The caller writes its own error envelope on failure.

func WriteError

func WriteError(w http.ResponseWriter, status int, message string)

WriteError writes an error envelope using models.ErrorResponse so all API versions return errors in the same shape.

func WriteJSON

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

WriteJSON serializes value as JSON and writes it with the given status.

func WriteStoreAwareError

func WriteStoreAwareError(logger *slog.Logger, w http.ResponseWriter, err error)

WriteStoreAwareError maps the small set of well-known service-layer error kinds to HTTP responses. The mapping (404 for missing sandboxes, 503 for capacity/topology admission failures, 400 for everything else) is a contract clients depend on regardless of API version, so it lives here in the shared helper package.

Types

This section is empty.

Jump to

Keyboard shortcuts

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