Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SnapshotObj ¶
type SnapshotObj struct {
// contains filtered or unexported fields
}
SnapshotObj is an immutable metadata snapshot of the static tree. After New, fields are read-only, so concurrent serving needs no locks.
func New ¶
New builds an immutable metadata snapshot of dir.
Safety and bounds are fail-closed at startup, not during requests:
- symlinks, devices, and sockets are skipped; only regular files are served;
- deny rules apply to web paths by extension or prefix, case-insensitively;
- per-file and total size are capped by maxSize; overflow is an error.
Map keys are cleaned absolute web paths, so "../" cannot escape the root and serving uses exact lookup only.
func (*SnapshotObj) Serve ¶
func (obj *SnapshotObj) Serve(w http.ResponseWriter, r *http.Request)
Serve returns a file from the metadata snapshot; directories and "/" resolve to index_file. http.ServeContent handles Range, If-Range, status codes, and Last-Modified over the opened file. If-None-Match is handled by the ETag header, and files open only after snapshot lookup.
func (*SnapshotObj) SetCacheMaxAge ¶
func (obj *SnapshotObj) SetCacheMaxAge(maxAge time.Duration)
SetCacheMaxAge sets Cache-Control max-age for served files. Negative values are ignored; call before serving because the snapshot is read-only afterwards.