httpcommon

package
v0.0.0-...-0789816 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestHeaderListSize = errors.New("request header list larger than peer's advertised limit")
)

Functions

func ActualContentLength

func ActualContentLength(req *http.Request) int64

ActualContentLength returns a sanitized version of req.ContentLength, where 0 actually means zero (not unknown) and -1 means unknown.

func CachedCanonicalHeader

func CachedCanonicalHeader(v string) (string, bool)

CachedCanonicalHeader returns the canonical form of a well-known header name.

func CanonicalHeader

func CanonicalHeader(v string) string

CanonicalHeader canonicalizes a header name. (For example, "host" becomes "Host".)

func IsRequestGzip

func IsRequestGzip(req *http.Request, disableCompression bool) bool

IsRequestGzip reports whether we should add an Accept-Encoding: gzip header for a request.

func LowerHeader

func LowerHeader(v string) (lower string, ascii bool)

LowerHeader returns the lowercase form of a header name, used on the wire for HTTP/2 and HTTP/3 requests.

Types

type EncodeHeadersParam

type EncodeHeadersParam struct {
	Request *http.Request

	// AddGzipHeader indicates that an "accept-encoding: gzip" header should be
	// added to the request.
	AddGzipHeader bool

	// PeerMaxHeaderListSize, when non-zero, is the peer's MAX_HEADER_LIST_SIZE setting.
	PeerMaxHeaderListSize uint64

	// DefaultUserAgent is the User-Agent header to send when the request
	// neither contains a User-Agent nor disables it.
	DefaultUserAgent string

	// HeaderOrder is for ResponseWriter.Header map keys
	// that, if present, defines a header order that will be used to
	// write the headers onto wire. The order of the slice defined how the headers
	// will be sorted. A defined Key goes before an undefined Key.
	//
	// This is the only way to specify some order, because maps don't
	// have a stable iteration order. If no order is given, headers will
	// be sorted lexicographically.
	//
	// According to RFC2616 it is good practice to send general-header fields
	// first, followed by request-header or response-header fields and ending
	// with entity-header fields.
	HeaderOrder []string

	// PHeaderOrder is for setting http2 pseudo header order.
	// If is nil it will use regular GoLang header order.
	// Valid fields are :authority, :method, :path, :scheme
	PHeaderOrder []string
}

EncodeHeadersParam is parameters to EncodeHeaders.

type EncodeHeadersResult

type EncodeHeadersResult struct {
	HasBody     bool
	HasTrailers bool
}

EncodeHeadersParam is the result of EncodeHeaders.

func EncodeHeaders

func EncodeHeaders(param EncodeHeadersParam, headerf func(name, value string)) (res EncodeHeadersResult, _ error)

EncodeHeaders constructs request headers common to HTTP/2 and HTTP/3. It validates a request and calls headerf with each pseudo-header and header for the request. The headerf function is called with the validated, canonicalized header name.

Jump to

Keyboard shortcuts

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