httpheader

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package httpheader provides HTTP Header related functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptSpec

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

	// NOTE: Set and Add allow empty value.
	Set map[string]string `json:"set,omitempty"`
	Add map[string]string `json:"add,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)

Adapt adapts HTTPHeader according to AdaptSpec.

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

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 `json:"values,omitempty" jsonschema:"uniqueItems=true"`
	Regexp string   `json:"regexp,omitempty" jsonschema:"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