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:
- Looks up the requested file in the cache to obtain ETag and LastModified.
- Handles If-None-Match → 304 Not Modified.
- Handles If-Modified-Since → 304 Not Modified.
- 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.