cacheheaders

package
v0.152.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 3 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 {
	MaxAge               int64
	Public               bool
	StaleWhileRevalidate int64
}

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)

func (*Headers) CacheControl

func (c *Headers) CacheControl() string

CacheControl returns the value of the configured Cache-Control header

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(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