Module aitch::handlers::static_files [−][src]
Handlers which serve static files (such as assets) from disk.
This module provides two handlers, for use in development only:
static_file_handler(file_path)
: serves a file from disk in response to any HTTP request.static_files_handler(directory_path)
: serves files from a directory, based on the path of incoming HTTP requests.
MIME types
By default these handlers will use the mime_guess
crate in order to guess the MIME type of
the file being served (based on file extension only), and will use this to set the
Content-Type
header in the response.
This feature can be disabled by the mime_guess
feature on the aitch crate, which removes the
dependency on mime_guess
. If the feature is disabled, all responses will be served with
Content-Type: application/octet-stream
.
I/O errors
Any I/O errors that occur while reading files from disk (including file or directory not found) are silently returned as HTTP 404 responses.
Security
These handlers aim to be secure and protect against directory traversal attacks. However, it is recommended that these handlers only be used in development, and that in any production system, static assets are served by a separate server, such as nginx or Apache.
Functions
static_file_handler |
Serves a file from disk in response to any HTTP request. |
static_files_handler |
Serves files from a directory, based on the path of incoming HTTP requests. |