httputil

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package httputil provides common HTTP utilities shared across servers.

Index

Constants

View Source
const MaxRequestBodySize = 1 << 20

MaxRequestBodySize is the maximum allowed request body size (1MB). This prevents memory exhaustion attacks via large payloads.

Variables

This section is empty.

Functions

func DecodeJSON

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

DecodeJSON decodes JSON from the request body into the target. It uses LimitedBody to prevent oversized payloads.

func LimitedBody

func LimitedBody(w http.ResponseWriter, r *http.Request, maxBytes int64) io.ReadCloser

LimitedBody wraps a request body with a size limit. Returns a ReadCloser that will return an error if the body exceeds maxBytes.

func WriteJSON

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

WriteJSON writes a JSON response with the given status code. It sets the Content-Type header to application/json.

Types

This section is empty.

Jump to

Keyboard shortcuts

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