Help us shape the future of Go! Take the 2026 Go Developer Survey

static

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package static is the edge static-asset handler (ADR-0120, F82): it serves a Bucket-prefix static site directly through the FEAT-0006 edge — index resolution, content-types, a weak (ModTime,Size) ETag + conditional GET (304), HTTP Range (206), an optional SPA fallback, and a pinned three-tier Cache-Control — with no function code and no activator hop. The bytes are the same per-namespace Bucket view the S3 frontend serves (ADR-0080), read over the blob.Bucket port.

Security (ADR-0120 B1): the traversal defense is OWNED here, not inherited from the blob driver. It path.Cleans the (already percent-decoded) request remainder, rejects any `..`-containing path, and asserts the resolved object key has the declared Prefix BEFORE any blob Get — no read can escape the prefix / bucket / namespace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketResolver

type BucketResolver func(ns v1.NamespaceName, bucket string) (blob.Bucket, bool)

BucketResolver resolves a (namespace, bucket) to its per-namespace blob view (the same s3BucketFor the S3 frontend uses, ADR-0080). ok=false ⇒ the Bucket is missing / cross-namespace.

type Deps

type Deps struct {
	Buckets BucketResolver
	Logger  *slog.Logger
}

Deps are the Handler's dependencies.

type Handler

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

Handler serves a Bucket-prefix static site over the edge (F82). It resolves it, it does not proxy — there is no function to wake.

func New

func New(d Deps) (*Handler, error)

New builds the static Handler.

func (*Handler) Serve

func (h *Handler) Serve(w http.ResponseWriter, r *http.Request, ns v1.NamespaceName, back *v1.StaticBackend, remainder string)

Serve writes the object at <back.Prefix><cleaned-remainder> in back.Bucket. remainder is the function-relative path (the matched Route prefix already stripped), always starting "/", and already percent-decoded (it is cut from r.URL.Path, which net/http decodes), so it is not decoded again. It owns the 405 (non-GET/HEAD), the traversal defense (B1), the weak (ModTime,Size) ETag validator (M1), the three-tier Cache-Control (M3), index resolution and the SPA fallback; the stdlib http.ServeContent handles Last-Modified / If-Modified-Since / If-Range / If-None-Match → 304 / Range → 206.

Jump to

Keyboard shortcuts

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