httputil

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package httputil provides HTTP utilities for safe request/response handling.

Index

Constants

View Source
const (
	// MaxErrorBodySize is the maximum size for error response bodies (64KB).
	MaxErrorBodySize int64 = 64 * 1024

	// MaxJSONBodySize is the maximum size for JSON response bodies (1MB).
	MaxJSONBodySize int64 = 1024 * 1024

	// MaxFileBodySize is the maximum size for file downloads (100MB).
	MaxFileBodySize int64 = 100 * 1024 * 1024
)

Default limits for response body reads.

Variables

This section is empty.

Functions

func LimitReader

func LimitReader(r io.Reader, n int64) io.Reader

LimitReader wraps io.LimitReader for consistency.

func ReadErrorBody

func ReadErrorBody(r io.Reader) ([]byte, error)

ReadErrorBody reads an error response body with a safe limit. Useful for reading error messages from failed HTTP responses.

func ReadJSONBody

func ReadJSONBody(r io.Reader) ([]byte, error)

ReadJSONBody reads a JSON response body with a safe limit.

func ReadLimited

func ReadLimited(r io.Reader, limit int64) ([]byte, error)

ReadLimited reads up to limit bytes from r. Returns an error if the content exceeds the limit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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