Expand description
Serving files from disk
serve_file answers a request with a file: Content-Type from the
extension, Last-Modified and a weak ETag, conditional requests (304),
byte ranges (206, 416, If-Range) for resumable downloads and media
seeking, and bodies streamed in chunks so large files never sit in memory.
HEAD works through the router.
use ullun::files::{serve_file, FileOptions};
use ullun::prelude::*;
async fn report(req: Request) -> Result<Response> {
// path chosen by the server, never built from client input
serve_file(&req, "/var/data/report.pdf", &FileOptions::new().attachment("report.pdf")).await
}The caller is responsible for the path: never join client-supplied names onto
a directory without validating them (see App::serve_static, which does).
Structs§
- File
Options - Per-response settings
Functions§
- content_
type_ for Content-Typefor a path, by extension (application/octet-streamif unknown)- http_
date - HTTP date (IMF-fixdate), e.g.
Sun, 06 Nov 1994 08:49:37 GMT - http_
date_ now - Current time as an HTTP date
- parse_
http_ date - Parse an IMF-fixdate (the only format servers must generate)
- serve_
file - Serve
path, honouring conditional and range headers ofreq