httpheader

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyCacheControl is the key of Cache-Control.
	KeyCacheControl = "Cache-Control"
	// KeyAcceptEncoding is the key of Accept-Encoding.
	KeyAcceptEncoding = "Accept-Encoding"
	// KeyContentEncoding is the key of Content-Encoding.
	KeyContentEncoding = "Content-Encoding"
	// KeyContentLength is the key of Content-Length.
	KeyContentLength = "Content-Length"
	// KeyVary is the key of Vary.
	KeyVary = "Vary"

	// KeyXForwardedFor is the key of X-Forwarded-For.
	KeyXForwardedFor = "X-Forwarded-For"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptSpec

type AdaptSpec struct {
	Del []string `yaml:"del" jsonschema:"omitempty,uniqueItems=true"`

	// NOTE: Set and Add allow empty value.
	Set map[string]string `yaml:"set" jsonschema:"omitempty"`
	Add map[string]string `yaml:"add" jsonschema:"omitempty"`
}

AdaptSpec describes rules for adapting.

type HTTPHeader

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

HTTPHeader is the wrapper of http.Header with more abilities.

func New

func New(src http.Header) *HTTPHeader

New creates an HTTPHeader.

func (*HTTPHeader) Adapt

func (h *HTTPHeader) Adapt(as *AdaptSpec, te texttemplate.TemplateEngine)

Adapt adapts HTTPHeader according to AdaptSpec. Using templateEngine if value contain any valid template

func (*HTTPHeader) Add

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

Add adds the key value pair.

func (*HTTPHeader) AddFrom

func (h *HTTPHeader) AddFrom(src *HTTPHeader)

AddFrom adds values from another HTTPHeader.

func (*HTTPHeader) AddFromStd

func (h *HTTPHeader) AddFromStd(src http.Header)

AddFromStd wraps AddFrom by replacing the parameter type *HTTPHeader with standard http.Header.

func (*HTTPHeader) Copy

func (h *HTTPHeader) Copy() *HTTPHeader

Copy copies HTTPHeader to a whole new HTTPHeader.

func (*HTTPHeader) Del

func (h *HTTPHeader) Del(key string)

Del deletes the key value pair by the key.

func (*HTTPHeader) Get

func (h *HTTPHeader) Get(key string) string

Get gets the FIRST value by the key.

func (*HTTPHeader) GetAll

func (h *HTTPHeader) GetAll(key string) []string

GetAll gets all values of the key.

func (*HTTPHeader) Length added in v1.3.2

func (h *HTTPHeader) Length() int

Length returns the length of the header in serialized format

func (*HTTPHeader) Reset

func (h *HTTPHeader) Reset(src http.Header)

Reset resets internal src http.Header.

func (*HTTPHeader) Set

func (h *HTTPHeader) Set(key, value string)

Set the key value pair of headers.

func (*HTTPHeader) SetFrom

func (h *HTTPHeader) SetFrom(src *HTTPHeader)

SetFrom sets values from another HTTPHeader.

func (*HTTPHeader) SetFromStd

func (h *HTTPHeader) SetFromStd(src http.Header)

SetFromStd wraps Setfrom by replacing the parameter type *HTTPHeader with standard http.Header.

func (*HTTPHeader) Std

func (h *HTTPHeader) Std() http.Header

Std returns internal Header of standard library.

func (*HTTPHeader) VisitAll

func (h *HTTPHeader) VisitAll(fn func(key, value string))

VisitAll call fn with every key value pair.

type Validator

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

Validator is the entity standing for all operations to HTTPHeader.

func NewValidator

func NewValidator(spec *ValidatorSpec) *Validator

NewValidator creates a validator.

func (Validator) Validate

func (v Validator) Validate(h *HTTPHeader) error

Validate validates HTTPHeader by the Validator.

type ValidatorSpec

type ValidatorSpec map[string]*ValueValidator

ValidatorSpec describes Validator

type ValueValidator

type ValueValidator struct {
	// NOTE: It allows empty value.
	Values []string `yaml:"values" jsonschema:"omitempty,uniqueItems=true"`
	Regexp string   `yaml:"regexp" jsonschema:"omitempty,format=regexp"`
	// contains filtered or unexported fields
}

ValueValidator is the entity to validate value.

func (ValueValidator) Validate

func (vv ValueValidator) Validate() error

Validate validates ValueValidator.

Jump to

Keyboard shortcuts

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