httpx

package module
v0.0.0-...-9026fe8 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2025 License: MIT Imports: 8 Imported by: 0

README

httpx

CI codecovGo Report Card PkgGoDev

httpx/compress

Http middleware (inbound - todo) and RoundTripper (outbound) that handles compression (br.deflate,gzip,zstd).

httpx/log

Http middleware (inbound) and RoundTripper (outbound) using slog.

Inbound Logger (http middleware)

Inbound logger middleware (http handler) can be initialized with

A logger (WithLogger)

The logger that is set with this function is the logger will be used to log the traffic. If no logger is set the slog.Default() will be used.

A level (WithLogInLevel)

The level that is set with this function is the log level in which the middleware will log the traffic. Default value: slog.LevelDebug.

A log mode (WithMode)

The log mode can take two values Drain and Tee.

  • When Drain is selected the body of the income request is read entirely upon receiving and a copy of the body will be passed to the next http handlers.
  • When Tee is selected a tee reader wraps incoming request's body and then the request is passed to the next http handlers. The request body will be read when (and only) the next (or final) http handlers, read it. Default value: Drain.
A log policy (WithLogPolicy)

The log policy can indicate conditions

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrainAndCloseRequest

func DrainAndCloseRequest(req *http.Request) error

DrainAndCloseRequest can be used (most probably with defer) from the client side to ensure that the http request body is consumed til the end and closed.

func DrainAndCloseResponse

func DrainAndCloseResponse(res *http.Response) error

DrainAndCloseResponse can be used (most probably with defer) from the client side to ensure that the http response body is consumed til the end and closed.

func NewHTTPClient

func NewHTTPClient(globalTimeout time.Duration) *http.Client

NewHTTPClient returns a new default http client.

func Recoverer

func Recoverer(logger *slog.Logger) func(http.Handler) http.Handler

Recoverer returns a recoverer http middleware that logs every panic into the provided slog logger.

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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