httpcc

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 5 Imported by: 4

README

httpcc

Parses HTTP/1.1 Cache-Control header, and returns a struct that is convenient for the end-user to do what they will with.

Parsing the HTTP Request

dir, err := httpcc.ParseRequest(req.Header.Get(`Cache-Control`))
// dir.MaxAge()       uint64, bool
// dir.MaxStale()     uint64, bool
// dir.MinFresh()     uint64, bool
// dir.NoCache()      bool
// dir.NoStore()      bool
// dir.NoTransform()  bool
// dir.OnlyIfCached() bool
// dir.Extensions()   map[string]string

Parsing the HTTP Response

directives, err := httpcc.ParseResponse(res.Header.Get(`Cache-Control`))
// dir.MaxAge()         uint64, bool
// dir.MustRevalidate() bool
// dir.NoCache()        []string
// dir.NoStore()        bool
// dir.NoTransform()    bool
// dir.Public()         bool
// dir.Private()        bool
// dir.SMaxAge()        uint64, bool
// dir.Extensions()     map[string]string

Documentation

Index

Constants

View Source
const (
	// Request Cache-Control directives
	MaxAge       = "max-age" // used in response as well
	MaxStale     = "max-stale"
	MinFresh     = "min-fresh"
	NoCache      = "no-cache"     // used in response as well
	NoStore      = "no-store"     // used in response as well
	NoTransform  = "no-transform" // used in response as well
	OnlyIfCached = "only-if-cached"

	// Response Cache-Control directive
	MustRevalidate  = "must-revalidate"
	Public          = "public"
	Private         = "private"
	ProxyRevalidate = "proxy-revalidate"
	SMaxAge         = "s-maxage"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RequestDirective

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

func ParseRequest

func ParseRequest(v string) (*RequestDirective, error)

ParseRequest parses the content of `Cache-Control` header of an HTTP Request.

func (*RequestDirective) Extension

func (d *RequestDirective) Extension(s string) string

func (*RequestDirective) Extensions

func (d *RequestDirective) Extensions() map[string]string

func (*RequestDirective) MaxAge

func (d *RequestDirective) MaxAge() (uint64, bool)

func (*RequestDirective) MaxStale

func (d *RequestDirective) MaxStale() (uint64, bool)

func (*RequestDirective) MinFresh

func (d *RequestDirective) MinFresh() (uint64, bool)

func (*RequestDirective) NoCache

func (d *RequestDirective) NoCache() bool

func (*RequestDirective) NoStore

func (d *RequestDirective) NoStore() bool

func (*RequestDirective) NoTransform

func (d *RequestDirective) NoTransform() bool

func (*RequestDirective) OnlyIfCached

func (d *RequestDirective) OnlyIfCached() bool

type ResponseDirective

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

func ParseResponse

func ParseResponse(v string) (*ResponseDirective, error)

ParseResponse parses the content of `Cache-Control` header of an HTTP Response.

func (*ResponseDirective) Extension

func (d *ResponseDirective) Extension(s string) string

func (*ResponseDirective) Extensions

func (d *ResponseDirective) Extensions() map[string]string

func (*ResponseDirective) MaxAge

func (d *ResponseDirective) MaxAge() (uint64, bool)

func (*ResponseDirective) NoCache

func (d *ResponseDirective) NoCache() []string

func (*ResponseDirective) NoStore

func (d *ResponseDirective) NoStore() bool

func (*ResponseDirective) NoTransform

func (d *ResponseDirective) NoTransform() bool

func (*ResponseDirective) Private

func (d *ResponseDirective) Private() []string

func (*ResponseDirective) ProxyRevalidate

func (d *ResponseDirective) ProxyRevalidate() bool

func (*ResponseDirective) Public

func (d *ResponseDirective) Public() bool

func (*ResponseDirective) SMaxAge

func (d *ResponseDirective) SMaxAge() (uint64, bool)

type TokenPair

type TokenPair struct {
	Name  string
	Value string
}

func ParseRequestDirective

func ParseRequestDirective(s string) (*TokenPair, error)

ParseRequestDirective parses a single token.

func ParseRequestDirectives

func ParseRequestDirectives(s string) ([]*TokenPair, error)

func ParseResponseDirective

func ParseResponseDirective(s string) (*TokenPair, error)

func ParseResponseDirectives

func ParseResponseDirectives(s string) ([]*TokenPair, error)

type TokenValuePolicy

type TokenValuePolicy int
const (
	NoArgument TokenValuePolicy = iota
	TokenOnly
	QuotedStringOnly
	AnyTokenValue
)

Jump to

Keyboard shortcuts

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