#http #serve #file #headers

http-file-headers

A framework-agnostic helper library for serving static files. It makes very easy to write full-featured static file server (incl. conditional headers, encodings, range requests, etc)

7 releases

Uses old Rust 2015

0.1.8 Jun 27, 2018
0.1.7 Jun 27, 2018
0.1.6 Dec 29, 2017
0.1.3 Sep 6, 2017
0.1.2 Aug 25, 2017

#860 in HTTP server

Download history 29/week @ 2023-10-28 11/week @ 2023-11-04 9/week @ 2023-11-11 17/week @ 2023-11-18 29/week @ 2023-11-25 20/week @ 2023-12-02 10/week @ 2023-12-09 18/week @ 2023-12-16 22/week @ 2023-12-23 11/week @ 2023-12-30 11/week @ 2024-01-06 9/week @ 2024-01-13 14/week @ 2024-01-20 27/week @ 2024-01-27 10/week @ 2024-02-03 44/week @ 2024-02-10

97 downloads per month
Used in swindon

MIT/Apache

55KB
1.5K SLoC

Http-file-headers Crate

Github | Documentaion | Examples | Crate

A framework-agnostic library that parses file-related headers from HTTP request and helps serving files including support of:

  • ETag, If-None-Match
  • Last-Modified, If-Modified-Since
  • Accept-Ranges, Range, Content-Range
  • Content-Type using mime_guess
  • Accept-Encoding for serving compressed (gzip and brotli) files
  • Serving index.html or similar directory indexes

The library is not tied to any framework, HTTP or even async library. So it's usage is quite verbose (see example). Still it does most of the complex work internally and is easily adapted to different needs.

Here are just few things that example in < 200 LoCs shows:

  1. Tokio for asynchronous stuff
  2. Tk-http serving HTTP
  3. Futures-cpupool for offloading reading from disk into separate thread pool
  4. Adding custom headers and error pages
  5. Customizing path where file are served from

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~23K SLoC