bodylimit

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bodylimit provides HTTP middleware that caps the size of request bodies. Bodies whose declared size exceeds the cap are rejected early with 413 Request Entity Too Large; bodies with unknown or understated lengths are limited when downstream handlers read them.

It is used both directly as a net/http middleware (the management API and the vMCP server) and via the runner middleware registry (the MCP proxies), so every inbound listener can bound the memory a single request may consume before it is buffered by handlers that call io.ReadAll.

Index

Constants

View Source
const (
	// MiddlewareType is the type constant for the body limit middleware in the
	// runner middleware registry.
	MiddlewareType = "bodylimit"

	// DefaultMaxRequestBodySize is the generic request body fallback limit.
	DefaultMaxRequestBodySize = httplimit.DefaultMaxRequestBodySize
)

Variables

This section is empty.

Functions

func CreateMiddleware

func CreateMiddleware(config *types.MiddlewareConfig, runner types.MiddlewareRunner) error

CreateMiddleware is the types.MiddlewareFactory registered in the runner's GetSupportedMiddlewareFactories. It unmarshals MiddlewareParams, builds the handler via Middleware, and registers it with the runner.

func IsRequestTooLarge

func IsRequestTooLarge(err error) bool

IsRequestTooLarge forwards the overflow check to the generic implementation.

func Middleware

func Middleware(maxBytes int64) func(http.Handler) http.Handler

Middleware forwards to the standard-library-only body-limit implementation.

Types

type MiddlewareParams

type MiddlewareParams struct {
	// MaxBytes is the maximum request body size in bytes. Values <= 0 are
	// treated as DefaultMaxRequestBodySize (zero never means "unlimited").
	MaxBytes int64 `json:"max_bytes"`
}

MiddlewareParams holds the parameters for the body limit middleware factory.

Directories

Path Synopsis
Package httplimit provides generic HTTP request-body limiting middleware.
Package httplimit provides generic HTTP request-body limiting middleware.

Jump to

Keyboard shortcuts

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