reqbody

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package reqbody centralizes bounded HTTP request body reads for frontend handlers.

Index

Constants

View Source
const DefaultMaxBytes int64 = 8 << 20

DefaultMaxBytes is the maximum request body size when no explicit limit is set.

Variables

This section is empty.

Functions

func ReadAll

func ReadAll(w http.ResponseWriter, r *http.Request, maxBytes int64) (data []byte, err error)

ReadAll reads r.Body using http.MaxBytesReader. On limit exceeded it returns a non-nil err for which TooLarge returns true; callers should respond with HTTP 413 without treating it as JSON parse failure.

When the request advertises Content-Encoding: gzip, the body is transparently decompressed and the byte limit is applied to the decompressed size (mitigating decompression bombs).

func TooLarge

func TooLarge(err error) bool

TooLarge reports whether err is from exceeding MaxBytesReader's limit. It uses errors.As so any error in the chain that unwraps to *http.MaxBytesError matches.

Types

This section is empty.

Jump to

Keyboard shortcuts

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