headers

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEncoding = "iso-8859-1"

Variables

This section is empty.

Functions

func CharsetOf

func CharsetOf(str string) string

CharsetOf returns a charset parameter value, returning DefaultEncoding in case not presented

func ParamOf

func ParamOf(str, key string) string

ParamOf is an alias to ParamOfOr, except no `or`-parameter is passed - empty string will be returned in case not found.

func ParamOfOr

func ParamOfOr(str, key, or string) string

ParamOfOr looks for a parameter in a value, and if found, returns a parameter value. In case parameter is not found, `or` is returned

func QualityOf

func QualityOf(str string) int

QualityOf simply returns a value of quality-parameter as an uint8. If not presented or is not a valid integer, 9 is returned

func ValueOf

func ValueOf(str string) string

ValueOf returns a value until first semicolon is met. Even if the value after semicolon is not a parameter, it will anyway be counted as a parameter

Types

type Encoding added in v0.9.0

type Encoding struct {
	// Transfer represents Transfer-Encoding header value, split by comma
	Transfer []string
	// Content represents Content-Encoding header value, split by comma
	Content []string
	// Chunked doesn't belong to any of encodings, as it is still must be processed individually
	Chunked, HasTrailer bool
}

type Headers

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

Headers is a struct that encapsulates headers map from user, allowing only methods

func FromMap added in v0.9.3

func FromMap(m map[string][]string) *Headers

FromMap returns headers instance with already inserted values from given map. Note: as maps are unordered, resulting Headers instance will also contain unordered pairs (but guaranteed to be grouped together)

func NewHeaders

func NewHeaders() *Headers

NewHeaders returns new empty instance of Headers

func NewPreallocHeaders added in v0.9.3

func NewPreallocHeaders(n int) *Headers

NewPreallocHeaders returns empty Headers instance with pre-allocated storage for exactly n pairs (two different values of a single header are also counted as two pairs)

func (*Headers) Add

func (h *Headers) Add(key, value string)

Add values to the key. In case did not exist, it'll be created

func (*Headers) Clear

func (h *Headers) Clear()

Clear headers map. Is a system method, that is not supposed to be ever called by user

func (*Headers) Get added in v0.8.1

func (h *Headers) Get(key string) (string, bool)

Get behaves just as map lookup. It returns both desired string and bool flag meaning the success of the operation (false=no such key, true=found)

func (*Headers) Has

func (h *Headers) Has(key string) bool

Has returns true or false depending on whether such a key exists

func (*Headers) Iter added in v0.9.2

func (h *Headers) Iter() iter.Iterator[[]string]

Iter returns an iterator over all the header key-value pairs (each pair is exactly 2 values). Note: these pairs aren't sorted nor unique, so multiple Constant-Header: <some value> pairs may have any other pairs between

func (*Headers) Keys added in v0.9.2

func (h *Headers) Keys() []string

Keys returns all the unique keys

func (*Headers) KeysIter added in v0.6.0

func (h *Headers) KeysIter() iter.Iterator[string]

KeysIter returns an iterator over all unique keys

func (*Headers) Unwrap

func (h *Headers) Unwrap() []string

Unwrap returns an underlying map as it is. This means that modifying it will also affect Headers object

func (*Headers) Value

func (h *Headers) Value(key string) string

Value does the same as ValueOr does but returning an empty string by default

func (*Headers) ValueOr

func (h *Headers) ValueOr(key, or string) string

ValueOr returns a header value, or custom value instead

func (*Headers) Values

func (h *Headers) Values(key string) (values []string)

Values returns all the values of a key

func (*Headers) ValuesIter added in v0.6.0

func (h *Headers) ValuesIter(key string) iter.Iterator[string]

ValuesIter returns an iterator over all the values of a key

Jump to

Keyboard shortcuts

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