#static-file #static #pingora #web-server #http

resource-proxy-pingora

A Pingora module for serving static files

3 releases

0.1.2 Nov 4, 2024
0.1.1 Aug 20, 2024
0.1.0 Aug 20, 2024

#368 in HTTP server

Download history 242/week @ 2024-08-16 25/week @ 2024-08-23 26/week @ 2024-09-13 13/week @ 2024-09-20 21/week @ 2024-09-27 4/week @ 2024-10-04 123/week @ 2024-11-01 11/week @ 2024-11-08 3/week @ 2024-11-15 1/week @ 2024-11-22

138 downloads per month

Apache-2.0

140KB
2.5K SLoC

This is a fork from Pandora Web Server

some clean and remove from origin module

Static Files module for Pandora Web Server

The Static Files module allows serving static files from a directory.

Supported functionality

  • GET and HEAD requests
  • Configurable directory index files
  • A page can be configured to display on 404 Not Found errors instead of the standard error page.
  • Conditional requests via If-Modified-Since, If-Unmodified-Since, If-Match, If-None match HTTP headers
  • Byte range requests via Range and If-Range HTTP headers
  • Serving pre-compressed versions of files (gzip, zlib deflate, compress, Brotli, Zstandard algorithms supported)

Known limitations

  • Requests with multiple byte ranges are not supported and will result in the full file being returned. The complexity required for implementing this feature isn’t worth this rare use case.
  • Zero-copy data transfer (a.k.a. sendfile) cannot currently be supported within the Pingora framework.

Compression support

You can activate support for selected compression algorithms via the precompressed configuration setting, e.g. with this configuration:

root: /var/www/html
precompressed:
- gz
- br

With this configuration, a request for /file.txt might result in the file /file.txt.gz or /file.txt.br being returned if present in the directory and supported by the client. If multiple supported pre-compressed files exist, one is chosen according to the client’s preferences communicated in the Accept-Encoding HTTP header.

If pre-compressed files are disabled or no supported variant is found, the response might still get dynamically compressed. The Compression module can be used to activate dynamic compression.

Configuration settings

Configuration setting Command line Type Default value Description
root --root directory path The directory to serve static files from
canonicalize_uri --canonicalize-uri boolean true If true, requests to /file%2etxt will be redirected to /file.txt and requests to /dir redirected to /dir/
index_file --index-file list of strings [] When a directory is requested, look for these files within to directory and show the first one if found instead of the usual 403 Forbidden error
page_404 --page-404 URI If set, this page will be displayed instead of the standard 404 Not Found error
precompressed --precompressed list of file extensions [] File extensions of pre-compressed files to look for. Supported extensions are gz (gzip), zz (zlib deflate), z (compress), br (Brotli), zst (Zstandard).
declare_charset --declare-charset character set "utf-8" A character set to declare for text files
declare_charset_types --declare_charset_types list of MIME types ["text/*", "*+xml", "*+json", "application/javascript", "application/json", "application/json5"] MIME types that declare_charset setting should apply to

Specifying MIME types

The declare_charset_types setting is a list of MIME types. Each entry should be specified in one of the following formats:

  • *: Applies to any MIME type.
  • text/*: Type match, applies to any MIME type where the type part is text. This is processed more efficiently than prefix matches.
  • image/svg*: Prefix match, applies to any MIME type starting with image/svg.
  • *+xml: Suffix match, applies to any MIME type ending with +xml.
  • application/javascript: Exact match, applies only to application/javascript MIME type.

Dependencies

~30–42MB
~814K SLoC