httpx

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 20 Imported by: ? 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 carries the request and response semantics the service had under fiber onto net/http, so the HTTP contract stays byte-identical across the move. scripts/e2e-golden is the contract; the comments here say which fiber behaviour each piece reproduces.

Index

Constants

View Source
const (
	TextMethodNotAllowed = "Method Not Allowed"
	TextUpgradeRequired  = "Upgrade Required"
	TextUnauthorized     = "Unauthorized"
	TextInvalidMethod    = "Invalid http method"
	TextTooLarge         = "Request Entity Too Large"
)

Bodies of the plain-text answers fiber produced itself.

Variables

View Source
var ErrUnprocessableEntity = errors.New("Unprocessable Entity")

ErrUnprocessableEntity is what fiber's BodyParser returned for a content type it could not bind.

Functions

func BindBody

func BindBody(r *http.Request, out any) error

BindBody is fiber's BodyParser: JSON for any "+json"/"json" type, form fields for urlencoded and multipart bodies, XML, and an error otherwise.

func Bytes

func Bytes(w http.ResponseWriter, status int, contentType string, body []byte)

Bytes writes a complete body with an explicit length. net/http would switch to chunked encoding above 2 KB, which fasthttp never did for a buffered body.

func DetectionPath

func DetectionPath(raw string) string

DetectionPath is fiber's routing view of a path: ASCII lower-cased and without trailing slashes. Its length equals the raw path's minus those slashes, which is what lets Param slice values out of the raw path.

func DropLate

func DropLate(w http.ResponseWriter)

DropLate forgets registered late headers: a panic unwound past the fiber middleware that would have set them.

func FormFile

func FormFile(r *http.Request, key string) (*multipart.FileHeader, error)

FormFile returns the first file part under key.

func FormValue

func FormValue(r *http.Request, key string) string

FormValue looks up a value where fasthttp did, in this order: query string, urlencoded body, multipart body. An empty value falls through to the next.

func JSON

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

JSON writes v as fiber's c.JSON did: encoding/json.Marshal (sorted map keys, HTML escaped, no trailing newline) and Content-Type application/json.

func Late

func Late(w http.ResponseWriter, fn func(http.Header))

Late registers headers to apply when the status is written.

func MultipartForm

func MultipartForm(r *http.Request) (*multipart.Form, error)

MultipartForm parses the body once. Parts over multipartMemory spill to temp files, which Prepare removes when the request ends.

func Param

func Param(r *http.Request, name string) string

Param returns a route parameter as fiber's c.Params did: original case and encoding, with trailing slashes left out of a trailing wildcard. "*" names the wildcard; a parameter the matched route does not have is "".

func Prepare

func Prepare(next http.Handler) http.Handler

Prepare records the raw path and routes chi on fiber's detection path. It has to run inside the chi mux, where the route context already exists.

It also removes the temp files of every multipart form parsed below it: net/http only cleans up the form of the request it created, and handlers parse on copies made by WithContext.

func Query

func Query(r *http.Request, key string) string

Query returns the first value of a query argument, as fasthttp's Peek did.

func RawPath

func RawPath(r *http.Request) string

RawPath is the path exactly as the client sent it, undecoded, which is what fiber matched against and handed to handlers (fasthttp's PathOriginal).

func SendFile

func SendFile(w http.ResponseWriter, r *http.Request, path string)

SendFile answers with a file the way fiber's c.SendFile did through fasthttp's file server: Last-Modified and If-Modified-Since, single byte ranges, and for 304 and 416 a response reset of everything set earlier.

func SendStream

func SendStream(w http.ResponseWriter, r *http.Request, body io.ReadCloser, size int64)

SendStream is fiber's c.SendStream(r, size): a known length, then the stream, closed afterwards. A HEAD request closes it unread, as fasthttp's SkipBody did; net/http would discard the bytes, but only after pulling the whole object out of MinIO, or out of S3 on the archive path.

func Text

func Text(w http.ResponseWriter, status int, body string)

Text writes a plain-text body the way fiber's default error handler did.

func Wrap

func Wrap(writeTimeout time.Duration, next http.Handler) http.Handler

Wrap installs the Writer for every request. writeTimeout restarts the write deadline when the response starts, as fasthttp did: net/http's WriteTimeout alone runs from the end of the request headers, so a slow upload plus its processing would eat into the time left to answer.

Types

type Handler

type Handler func(http.ResponseWriter, *http.Request) error

Handler is a handler that may return an error, as fiber handlers did. A returned error becomes fiber's default error response: 500, text/plain, the error text.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Writer

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

Writer is the one ResponseWriter wrapper of a request, installed by Wrap.

Late headers reproduce fiber middleware that set headers after c.Next(): they are applied when the status is written, innermost first, so an outer middleware's value wins exactly as it did when it ran last.

func From

func From(w http.ResponseWriter) *Writer

From returns the request's Writer, or nil when Wrap is not installed.

func (*Writer) Flush

func (w *Writer) Flush()

func (*Writer) Hijack

func (w *Writer) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack lets the websocket upgrade take the connection.

func (*Writer) ResetHeaders

func (w *Writer) ResetHeaders()

ResetHeaders drops every header set so far, as fasthttp's file server did by resetting the response for 304 and 416. Late headers survive: fiber's limiter set them after c.Next() returned, so after the reset.

func (*Writer) Status

func (w *Writer) Status() int

Status is the status written so far, 0 before the first write.

func (*Writer) Unwrap

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

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(code int)

Jump to

Keyboard shortcuts

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