serdir 0.2.0

helpers for conditional GET, HEAD, byte range serving, and gzip content encoding for static files and more with hyper and tokio
Documentation

serdir

CI

Rust helpers for serving HTTP GET and HEAD responses with hyper 1.x and tokio.

This crate provides utilities for serving static files in Rust web applications.

Features

  • Range requests
  • Large file support via chunked streaming
  • Live content changes
  • ETag header generation and conditional GET requests
  • Serving files that have been pre-compressed using gzip, brotli or zstd
  • Cached runtime compression of files using brotli
  • Content type detection based on filename extensions
  • Serving directory paths using index.html pages
  • Customizing 404 response content
  • Support for the Tower Service and Layer APIs

This crate is derived from http-serve.

Examples:

  • Serve a directory tree using hyper:
    $ cargo run --example hyper --features hyper .
    

Optional features

This project defines 3 optional build features that can be enabled at compile time:

  • runtime-compression - enables the cached compression strategy, i.e. runtime compression of served files using Brotli
  • tower - enables integration with Tower-based web frameworks like Axum and Poem by providing APIs to convert a ServedDir into a tower::Service or tower::Layer
  • hyper - enables direct integration with the hyper web server by providing APIs to convert a ServedDir into a hyper::Service

Authors

See the AUTHORS file for details.

License

Your choice of MIT or Apache; see LICENSE-MIT.txt or LICENSE-APACHE, respectively.