handler

package
v1.6.1 Latest Latest
Warning

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

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

Documentation

Overview

Package handler provides the core HTTP file-serving handler and middleware composition for the static web server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildHandler

func BuildHandler(cfg *config.Config, c *cache.Cache, pc ...*security.PathCache) fasthttp.RequestHandler

BuildHandler composes the full middleware chain and returns a ready-to-use fasthttp.RequestHandler. The chain is (outer to inner):

recovery → logging → security → compress → file handler

An optional *security.PathCache may be provided to cache path validation results and skip per-request filesystem syscalls for repeated URL paths.

func BuildHandlerQuiet

func BuildHandlerQuiet(cfg *config.Config, c *cache.Cache, pc ...*security.PathCache) fasthttp.RequestHandler

BuildHandlerQuiet is like BuildHandler but suppresses per-request access logging. Use this when the --quiet flag is set.

Types

type FileHandler

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

FileHandler serves static files from disk with caching and compression support.

func NewFileHandler

func NewFileHandler(cfg *config.Config, c *cache.Cache, pc ...*security.PathCache) *FileHandler

NewFileHandler creates a new FileHandler. absRoot is resolved via filepath.Abs so per-request path arithmetic is free of OS syscalls. An optional *PathCache allows cache-hit requests to resolve the safe filesystem path without a context allocation (PERF-001).

func (*FileHandler) HandleRequest added in v1.3.0

func (h *FileHandler) HandleRequest(ctx *fasthttp.RequestCtx)

HandleRequest handles a fasthttp request by resolving and serving the requested file.

func (*FileHandler) LoadSidecar added in v1.6.1

func (h *FileHandler) LoadSidecar(path string) []byte

LoadSidecar attempts to read a pre-compressed sidecar file. Returns nil if the sidecar does not exist, cannot be read, or fails validation. The path parameter must be constructed from a validated absolute filesystem path (e.g., absPath + ".gz") to ensure it remains within the root directory.

func (*FileHandler) ValidateSidecarPath added in v1.6.1

func (h *FileHandler) ValidateSidecarPath(sidecarPath string) (string, error)

ValidateSidecarPath validates that a sidecar file path is within the root directory. It uses filepath.Clean() to normalize the path (recognized by CodeQL as a sanitizer), then verifies the canonical path remains within the root via symlink resolution and prefix checking. Returns the validated path or an error if validation fails. This function is designed to be recognized by static analyzers as a path sanitizer.

Jump to

Keyboard shortcuts

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