httpcache

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package httpcache provides conditional request helpers for REST APIs.

The package is dependency-neutral and only works with standard HTTP validators: ETag, Last-Modified, If-None-Match, If-Modified-Since, If-Match, and If-Unmodified-Since.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetValidators

func SetValidators(w http.ResponseWriter, validators Validators)

SetValidators writes ETag and Last-Modified response headers when present.

func WriteNotModified

func WriteNotModified(w http.ResponseWriter, validators Validators)

WriteNotModified writes a 304 response with validators and no body.

func WritePreconditionFailed

func WritePreconditionFailed(w http.ResponseWriter)

WritePreconditionFailed writes a 412 Problem Details response.

Types

type Decision

type Decision struct {
	Status             int
	NotModified        bool
	PreconditionFailed bool
}

Decision describes the result of evaluating conditional request headers.

func EvaluateRead

func EvaluateRead(r *http.Request, validators Validators) Decision

EvaluateRead evaluates conditional read headers for GET or HEAD handlers.

func EvaluateWrite

func EvaluateWrite(r *http.Request, validators Validators) Decision

EvaluateWrite evaluates write preconditions for unsafe handlers.

type ETag

type ETag string

ETag is an HTTP entity tag, including quotes and optional weak prefix.

func HashETag

func HashETag(data []byte) ETag

HashETag builds a strong ETag from a SHA-256 hash of data.

func ParseETag

func ParseETag(value string) (ETag, error)

ParseETag validates and normalizes a single ETag.

func StrongETag

func StrongETag(value string) ETag

StrongETag builds a strong ETag from an opaque value.

func WeakETag

func WeakETag(value string) ETag

WeakETag builds a weak ETag from an opaque value.

func (ETag) IsWeak

func (e ETag) IsWeak() bool

IsWeak reports whether the ETag is weak.

func (ETag) String

func (e ETag) String() string

String returns the wire representation of the ETag.

type Validators

type Validators struct {
	ETag         ETag
	LastModified time.Time
}

Validators are the current validators for a representation.

Jump to

Keyboard shortcuts

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