headers

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package headers provides HTTP caching and response header middleware. It handles ETag/Last-Modified conditional requests (304 Not Modified) and sets appropriate Cache-Control headers based on file type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(c *cache.Cache, cfg *config.HeadersConfig, indexFile string, next http.Handler) http.Handler

Middleware returns an http.Handler that:

  1. Looks up the requested file in the cache to obtain ETag and LastModified.
  2. Handles If-None-Match → 304 Not Modified.
  3. Handles If-Modified-Since → 304 Not Modified.
  4. Sets Cache-Control, ETag, Last-Modified, and Vary headers.

If the file is not yet cached (cache miss at this stage), header setting is deferred — the file handler will populate the cache and the next request will receive full caching headers.

func SetFileHeaders

func SetFileHeaders(w http.ResponseWriter, urlPath string, f *cache.CachedFile, cfg *config.HeadersConfig)

SetFileHeaders writes ETag, Last-Modified, Cache-Control, and Vary response headers for a file that has just been loaded (possibly bypassing the middleware cache-check path). This is called directly from the file handler.

Types

This section is empty.

Jump to

Keyboard shortcuts

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