httpencoding

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: ISC Imports: 4 Imported by: 6

README

httpencoding

-- import "vimagination.zapto.org/httpencoding"

Package httpencoding provides a function to deal with the Accept-Encoding header.

Usage

func ClearEncoding
func ClearEncoding(r *http.Request)

ClearEncoding removes the Accept-Encoding header so that any further attempts to establish an encoding will simply used the default, plain text, encoding.

Useful when you don't want a handler down the chain to also handle encoding.

func HandleEncoding
func HandleEncoding(r *http.Request, h Handler) bool

HandleEncoding will process the Accept-Encoding header and calls the given handler for each encoding until the handler returns true.

This function returns true when the Handler returns true, false otherwise.

For the identity (plain text) encoding the encoding string will be the empty string.

The wildcard encoding () will, after the '', contain a semi-colon seperated list of all disallowed encodings (q=0).

func InvalidEncoding
func InvalidEncoding(w http.ResponseWriter)

InvalidEncoding writes the 406 header.

func IsDisallowedInWildcard
func IsDisallowedInWildcard(accept, encoding Encoding) bool

IsDisallowedInWildcard will return true if the given encoding is disallowed in the given accept string.

func IsWildcard
func IsWildcard(accept Encoding) bool

IsWildcard returns true when the given accept string is a wildcard match.

type Encoding
type Encoding string

Encoding represents an encoding string as used by the client. Examples are gzip, br and deflate.

type Handler
type Handler interface {
	Handle(encoding Encoding) bool
}

Handler provides an interface to handle an encoding.

The encoding string (e.g. gzip, br, deflate) is passed to the handler, which is expected to return true if no more encodings are required and false otherwise.

The empty string "" is used to signify the identity encoding, or plain text.

type HandlerFunc
type HandlerFunc func(Encoding) bool

HandlerFunc wraps a func to make it satisfy the Handler interface.

func (HandlerFunc) Handle
func (h HandlerFunc) Handle(e Encoding) bool

Handle calls the underlying func.

Documentation

Overview

Package httpencoding provides a function to deal with the Accept-Encoding header.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearEncoding

func ClearEncoding(r *http.Request)

ClearEncoding removes the Accept-Encoding header so that any further attempts to establish an encoding will simply used the default, plain text, encoding.

Useful when you don't want a handler down the chain to also handle encoding.

func HandleEncoding

func HandleEncoding(r *http.Request, h Handler) bool

HandleEncoding will process the Accept-Encoding header and calls the given handler for each encoding until the handler returns true.

This function returns true when the Handler returns true, false otherwise.

For the identity (plain text) encoding the encoding string will be the empty string.

The wildcard encoding (*) will, after the '*', contain a semi-colon seperated list of all disallowed encodings (q=0).

func InvalidEncoding

func InvalidEncoding(w http.ResponseWriter)

InvalidEncoding writes the 406 header.

func IsDisallowedInWildcard added in v1.1.0

func IsDisallowedInWildcard(accept, encoding Encoding) bool

IsDisallowedInWildcard will return true if the given encoding is disallowed in the given accept string.

func IsWildcard added in v1.1.0

func IsWildcard(accept Encoding) bool

IsWildcard returns true when the given accept string is a wildcard match.

Types

type Encoding

type Encoding string

Encoding represents an encoding string as used by the client. Examples are gzip, br and deflate.

type Handler

type Handler interface {
	Handle(encoding Encoding) bool
}

Handler provides an interface to handle an encoding.

The encoding string (e.g. gzip, br, deflate) is passed to the handler, which is expected to return true if no more encodings are required and false otherwise.

The empty string "" is used to signify the identity encoding, or plain text.

type HandlerFunc

type HandlerFunc func(Encoding) bool

HandlerFunc wraps a func to make it satisfy the Handler interface.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(e Encoding) bool

Handle calls the underlying func.

Jump to

Keyboard shortcuts

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