limits

package
v1.0.442 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package limits defines shared server network limits. Zero values select conservative defaults; negative values explicitly disable individual limits. Configure limits before starting a server.

Index

Constants

View Source
const (
	// DefaultHeaderTimeout bounds the time spent reading HTTP request headers.
	DefaultHeaderTimeout = 10 * time.Second
	// DefaultReadTimeout bounds the time spent reading an entire HTTP request.
	DefaultReadTimeout = 30 * time.Second
	// DefaultIdleTimeout bounds the wait for the next keepalive request.
	DefaultIdleTimeout = 60 * time.Second
	// DefaultHandshakeTimeout bounds TLS handshakes and protocol detection.
	DefaultHandshakeTimeout = 10 * time.Second
	// DefaultMaxRequestBody is the HTTP request body limit in bytes (10 MiB).
	DefaultMaxRequestBody = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Timeouts

type Timeouts struct {
	// Header sets net/http ReadHeaderTimeout for HTTP/1.x headers.
	// HTTP/2 has no per-stream header deadline in net/http.
	Header time.Duration `json:"header,omitempty" yaml:"header,omitempty"`
	// Read limits reading the whole HTTP request, including its body.
	Read time.Duration `json:"read,omitempty" yaml:"read,omitempty"`
	// Idle limits waiting for the next HTTP keepalive request.
	Idle time.Duration `json:"idle,omitempty" yaml:"idle,omitempty"`
	// Handshake limits cmux detection and transport's eager TLS handshake.
	// net/http TLS listeners use the smaller positive Header or Read deadline.
	Handshake time.Duration `json:"handshake,omitempty" yaml:"handshake,omitempty"`
}

Timeouts configures server read deadlines. Zero selects the default for that field; a negative duration disables it. These are read deadlines, not handler execution or response write deadlines. Streaming callers may need to raise or disable Read.

func (Timeouts) ApplyHTTP

func (t Timeouts) ApplyHTTP(s *http.Server)

ApplyHTTP sets the read deadlines on a server before it starts serving. Negative values are preserved to disable net/http's fallback deadlines.

func (Timeouts) WithDefaults

func (t Timeouts) WithDefaults() Timeouts

WithDefaults returns a copy with zero fields replaced by their defaults.

Jump to

Keyboard shortcuts

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