Documentation Language: Swift

Structure

StaticFileHandler

Handler for serving static files from a directory.

struct StaticFileHandler

Overview

This type provides secure file serving with path sanitisation to prevent directory traversal attacks. It supports automatic index file resolution for directory requests.

Overview

StaticFileHandler validates and sanitises all incoming request paths, ensuring they remain within the configured root directory. Directory requests are automatically redirected to index.html if present.

Security

The handler implements several security measures:

Topics

Creating a Handler

?
init(rootDirectory:)

Creates a new static file handler.

Handling Requests

F
handleRequest(uri:includeBody:)

Handles an HTTP request and returns an appropriate response.

Properties

V
rootDirectory

The root directory for serving files.

Relationships

Conforms To