decompress

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 7 Imported by: 0

README

Request decompression middleware

decompress expands Content-Encoding: gzip request bodies with both an absolute output limit and an expansion-ratio limit.

app.Post("/ingest",
    decompress.New(decompress.Config{
        MaxSize: 8 << 20,
        MaxExpansionRatio: 50,
    }),
    ingest,
)

The compressed wire body remains subject to the server's MaxRequestBodySize; MaxSize separately bounds the decoded body.

Documentation

Overview

Package decompress provides bounded request decompression.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooLarge         = errors.New("decompress: expanded body exceeds limit")
	ErrExpansionRatio   = errors.New("decompress: expansion ratio exceeds limit")
	ErrUnsupported      = errors.New("decompress: unsupported content encoding")
	ErrMalformedContent = errors.New("decompress: malformed compressed content")
)

Functions

func DecodeGzip

func DecodeGzip(src []byte, maxSize, maxRatio int) ([]byte, error)

DecodeGzip expands src with both an absolute limit and an expansion-ratio limit. The ratio check makes small, highly compressible bombs fail early.

func New

func New(config ...Config) fh.HandlerFunc

Types

type Config

type Config struct {
	MaxSize           int
	MaxExpansionRatio int
	Next              func(fh.Ctx) bool
}

Jump to

Keyboard shortcuts

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