timeout

package
v0.0.0-...-1452ce7 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 12 Imported by: 14 modules, 49 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timeout provides an http.Client that closes a connection if it takes too long to establish, or stays idle for too long.

Index

Constants

View Source
const (
	// DefaultConnectTimeout is the default duration we're willing to wait to establish a connection
	DefaultConnectTimeout time.Duration = 30 * time.Second
	// DefaultIdleTimeout is the duration after which, if there's no I/O activity, we declare a connection dead
	DefaultIdleTimeout = 60 * time.Second
)

Variables

View Source
var IgnoreCertificateErrors = os.Getenv("HTTPKIT_IGNORE_CERTIFICATE_ERRORS") == "1"

IgnoreCertificateErrors is a dangerous option that instructs all timeout clients to ignore HTTPS certificate errors. This is used mostly in development, to use debugging proxies together with any timeout-powered application.

Functions

func GetBPS

func GetBPS() float64

GetBPS returns the last measured number of bytes transferred in a 1-second interval as a floating point value.

func NewClient

func NewClient(connectTimeout time.Duration, readWriteTimeout time.Duration) *http.Client

NewClient returns a new http client with custom connect and r/w timeouts.

func NewDefaultClient

func NewDefaultClient() *http.Client

NewDefaultClient returns a new http client with default connect and r/w timeouts.

func SetBandwidth

func SetBandwidth(bytesPerSecond int64)

SetBandwidth caps reads and writes to bytesPerSecond across all connections. Anything below 1 lifts the cap. Transfers already waiting for bandwidth pick up the new rate within replanInterval.

func SetSimulateOffline

func SetSimulateOffline(enabled bool)

SetSimulateOffline enables or disables offline simulation. When enabled, all connection attempts will return a *net.OpError with "simulated offline" contained in its string representation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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