bodylimit

package
v3.1.36 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package bodylimit 限制请求体大小,防止恶意大 Body 导致 OOM。

使用方式:

app.Use(bodylimit.New(bodylimit.Config{MaxBytes: 10 << 20})) // 10MB

超过限制时返回 HTTP 413 Request Entity Too Large。 该中间件零开销 — 仅在超过 MaxBytes 时才触发错误响应。

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	MaxBytes: 10 << 20,
}

Functions

func New

func New(conf ...Config) core.HandlerFunc

New 返回请求体大小限制中间件。

Types

type Config

type Config struct {
	// MaxBytes 最大请求体字节数。0 表示不限制。
	MaxBytes int64
	// Skip 可选跳过函数,返回 true 时跳过该请求的大小检查
	Skip func(c core.Ctx) bool
}

Config 请求体大小限制配置

Jump to

Keyboard shortcuts

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