accept

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

README

accept

This library contains some fairly simple routines for dealing with HTTP Accept headers: Accept:, Accept-Language: and Accept-Encoding:. It's designed to aid in implementing content negotiation.

For a more full-featured content negotiation package, you might want to try github.com/kevinpollet/nego.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimValue

func TrimValue(v string) string

TrimValue un-quotes a quoted parameter value

Types

type Accept

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

Accept represents an Accept, Accept-Language or Accept-Encoding header.

func NewAccept

func NewAccept(hdr string) (*Accept, error)

NewAccept parses an Accept: header and returns an Accept object which can be used to carry out content negotiation.

func NewAcceptEncoding

func NewAcceptEncoding(hdr string) (*Accept, error)

NewAccept parses an Accept-Encoding: header and returns an Accept object which can be used to carry out content negotiation.

func NewAcceptLanguage

func NewAcceptLanguage(hdr string) (*Accept, error)

NewAccept parses an Accept-Language: header and returns an Accept object which can be used to carry out content negotiation.

func (*Accept) Contains

func (a *Accept) Contains(value string) bool

Contains checks whether the accept header matches a specific value we want to feed them.

func (*Accept) GlobEqual

func (a *Accept) GlobEqual(x, y string) bool

func (*Accept) Negotiate

func (a *Accept) Negotiate(me ...string) (string, *AcceptValue, error)

Negotiate works out which of their most preferred values we are willing to provide, given a list of values we are offering.

type AcceptValue

type AcceptValue struct {
	Value       string            // The acceptable value
	Params      map[string]string // Any pre-Q parameters (part of the value)
	Ext         map[string]string // Any additional post-Q parameters (not part of the value)
	Q           float64           // The q= value
	Specificity int               // The specificity of this value, used as a tie-breaker when Q values are equal
}

AcceptValue represents an individual clause from an Accept header.

Jump to

Keyboard shortcuts

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