cacheheaders

package
v0.180.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cacheheaders implements support HTTP headers related to caching.

Currently, the package handles Cache-Control, Age and ETag

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheControl

type CacheControl struct {
	// Public controls wether the Cache-Control is declared as public or private
	Public bool
	// MaxAge indicates the value of the max-age directive, set to <0 to disable
	MaxAge int64
	// StaleWhileRevalidate indicates the value of the stale-while-revalidate directive, set to <0 to disable
	StaleWhileRevalidate int64
	// MustRevalidate indicates whether a must-revalidate directive must be included in Cache-Control
	MustRevalidate bool

	// Override allows override the Cache-Control settings on a per-request basis.
	Override func(r *http.Request, cc CacheControl) CacheControl
}

CacheControl contains the configuration for the generated Cache-Control header

type Headers

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

Headers provides support for returning the cache related headers. To initialize a Headers, call New().

func New

func New(cacheControl *CacheControl, configHash string) *Headers

newCacheHandler returns a new cacheHandler from a *cacheConfig representing the cache configuration for an operation and the API configuration hash (typically from Api.ApiConfigHash) If cacheControl is nil, no Cache-Control header is added to responses.

func (*Headers) CacheControl

func (c *Headers) CacheControl(r *http.Request) string

CacheControl returns the value of the configured Cache-Control header for the given http.Request (which might be nil)

func (*Headers) ETag

func (c *Headers) ETag(data []byte) string

ETag returns a en ETag derived from the config hash and the received data

func (*Headers) NotModified

func (c *Headers) NotModified(r *http.Request, w http.ResponseWriter) bool

NotModified checks the request and response headers and if they indicate the the client already has the resource, sends an http.StatusNotModified and returns true. If the headers don't match, nothing is done and false is returned.

func (*Headers) Set

func (c *Headers) Set(r *http.Request, w http.ResponseWriter, data []byte)

Set sets all the cache related headers

func (*Headers) String

func (c *Headers) String() string

String returns a description of the Headers, used for log messages

Jump to

Keyboard shortcuts

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