httpx

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0 modules, 0 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 httpx holds the JSON response writers shared by the HTTP layers, so every one of them answers with the same envelope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flush added in v0.19.0

func Flush(w http.ResponseWriter)

Flush flushes w when it, or a writer it wraps, supports it.

func ReadFrom added in v0.19.0

func ReadFrom(w http.ResponseWriter, r io.Reader) (int64, error)

ReadFrom copies r to w, through w's own ReadFrom when it has one (the net/http response does, and uses sendfile for a file) and through a pooled buffer otherwise. Response-writer wrappers call it from their ReadFrom after they have done their header bookkeeping.

func WriteError

func WriteError(w http.ResponseWriter, status int, code, message string)

WriteError writes the {error, code} envelope with the given status.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON writes v as an application/json response with the given status.

Types

type ErrorBody

type ErrorBody struct {
	Error string `json:"error"`
	Code  string `json:"code"`
}

ErrorBody is the JSON envelope of an error response.

type StatusWriter added in v0.19.0

type StatusWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

StatusWriter is the response-writer wrapper the middleware chain shares: it records the status code the handler chose and is otherwise transparent.

Every wrapper in the chain that hides a method of the writer underneath costs something real. ReadFrom is the one that matters: net/http's response implements io.ReaderFrom and serves an *os.File with sendfile(2), but only when the writer handed to iocopy.Copy still exposes it. StatusWriter forwards ReadFrom, Flush and (through Unwrap, for http.ResponseController) Hijack, SetWriteDeadline and EnableFullDuplex.

func WrapStatus added in v0.19.0

func WrapStatus(w http.ResponseWriter) *StatusWriter

WrapStatus returns w as a StatusWriter. A writer that already is one is returned as is, so the layers that all want the status code (metrics, tracing, access log, audit) share a single wrapper per request.

func (*StatusWriter) Flush added in v0.19.0

func (w *StatusWriter) Flush()

Flush forwards to the underlying writer when it can flush.

func (*StatusWriter) ReadFrom added in v0.19.0

func (w *StatusWriter) ReadFrom(r io.Reader) (int64, error)

ReadFrom forwards to the underlying writer's ReadFrom, which is what lets a file be sent with sendfile(2). A writer underneath without ReadFrom gets a pooled copy through Write.

func (*StatusWriter) SetStatus added in v0.19.0

func (w *StatusWriter) SetStatus(code int)

SetStatus overrides the recorded status without touching the response, for a layer that knows what a later layer will answer (a panic becomes a 500).

func (*StatusWriter) Status added in v0.19.0

func (w *StatusWriter) Status() int

Status is the status code written so far, 200 while none was.

func (*StatusWriter) Unwrap added in v0.19.0

func (w *StatusWriter) Unwrap() http.ResponseWriter

Unwrap lets http.ResponseController reach the underlying writer.

func (*StatusWriter) WriteHeader added in v0.19.0

func (w *StatusWriter) WriteHeader(code int)

WriteHeader records code and forwards it.

Jump to

Keyboard shortcuts

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