httputil

package
v0.0.0-...-e308f56 Latest Latest
Warning

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

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

Documentation

Overview

Package httputil contains utilities for HTTP clients and servers.

Index

Constants

This section is empty.

Variables

View Source
var HopByHopHeaders = []string{
	"Connection",
	"Keep-Alive",
	"Proxy-Authenticate",
	"Proxy-Authorization",
	"Te",
	"Trailers",
	"Transfer-Encoding",
	"Upgrade",
	"Host",
}

HopByHopHeaders are hop-by-hop headers that should not be forwarded by proxies (RFC 7230).

View Source
var TransportHeaders = []string{
	"Content-Length",
	"Date",
	"Accept-Encoding",
	"User-Agent",
	"Transfer-Encoding",
	"Time-To-Live",
}

TransportHeaders are headers added by the HTTP transport layer that should not be cached.

Functions

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, r *http.Request, status int, msg string, args ...any)

ErrorResponse creates an error response with the given code and format, and also logs a message.

func Errorf

func Errorf(status int, format string, args ...any) error

func FilterHeaders

func FilterHeaders(headers http.Header, skip ...string) http.Header

FilterHeaders returns a copy of headers with the specified header keys removed.

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

Types

type HTTPError

type HTTPError struct {
	// contains filtered or unexported fields
}

func (HTTPError) Error

func (h HTTPError) Error() string

func (HTTPError) Unwrap

func (h HTTPError) Unwrap() error

func (HTTPError) WriteHTTP

func (h HTTPError) WriteHTTP(w http.ResponseWriter, r *http.Request)

WriteHTTP writes this error as an HTTP response.

type HTTPResponder

type HTTPResponder interface {
	error
	WriteHTTP(http.ResponseWriter, *http.Request)
}

HTTPResponder is an error that knows how to write itself as an HTTP response.

Jump to

Keyboard shortcuts

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