httpx

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package httpx gives each HTTP caller a transport of its own. A CloseIdleConnections on the process-wide http.DefaultTransport, which every httptest.Server.Close also does, breaks a caller's connections parked there (#287, #531, #564), so production code never uses http.DefaultClient or http.DefaultTransport (a forbidigo rule in .golangci.yml enforces it).

Index

Constants

View Source
const DrainLimit = 4 << 10

DrainLimit is the most of an unread response body that CloseBody discards.

Variables

This section is empty.

Functions

func Client

func Client(timeout time.Duration) *http.Client

Client returns a client over a new Transport; a zero timeout means none, as for http.DefaultClient.

func CloseBody added in v0.4.0

func CloseBody(body io.ReadCloser)

CloseBody discards at most DrainLimit bytes of body and closes it. A body read to EOF returns its keep-alive connection to the pool; a longer one closes the connection, so an unbounded answer is never read in full.

func NodeClient added in v0.4.0

func NodeClient(timeout time.Duration) *http.Client

NodeClient returns a client over a new NodeTransport; a zero timeout means none.

func NodeTransport added in v0.4.0

func NodeTransport() *http.Transport

NodeTransport returns a new transport, with a connection pool of its own, for calls that never leave this node: function and pool workers, provider engines and the daemon's own node-private servers (ADR-0155). Concurrent calls to one host reuse keep-alive connections (ADR-0041), and no proxy is used.

func Transport

func Transport() *http.Transport

Transport returns a new transport with http.DefaultTransport's settings, the environment proxy included, and a connection pool of its own, for destinations off this node. A pool whose every destination runs on this node uses NodeTransport (ADR-0155).

Types

This section is empty.

Jump to

Keyboard shortcuts

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