An http file server written in rust using tokio and
hyper.
Includes support for:
- http 1.1 / 2
- boxed responses (send large files frame by frame)
headrequestsrangerequests- encoded requests
Bash the following commands:
git clone https://github.com/herebythere/file_server
cargo install --path file_server/file_serverBash the following command:
file_serverThis will start file_server with using the cwd as a base directory.
Now files can be requested from the cwd at localhost:3000:
curl localhost:3000A valid JSON configuration file matches the following schema.
{
"directory": "./",
"host_and_port": "127.0.0.1:4000",
"content_encodings": ["gzip", "deflate", "br", "zstd"],
"filepath_404": "./404.html"
}Filepaths can be relative or absolute. Relative paths are "relative from" the filepath of the JSON configuration file.
The content_encodings and filepath_404 properties are optional.
Bash the following command to serve files based on a an example configuration:
file_server demo/demo.example.jsonOpen a browser and visit http://localhost:3000 and an encoded version of index.html will be delivered.
When a request has an accept-encoding header, file_server will return a corresponding zip-ed version of file if available.
So if a request has the following header:
Accept-Encoding: gzip;
And the target file has a correspponding gziped file:
index.html # source file
index.html.gz # gzipped fileFile_server will send the encoded file, if available. Otherwise, it serves the source file.
File_server does not encode or zip files ever.
This program serves static files. Just zip them up now to save memory resources.
File_server supports single range requests.
Bash the following command:
curl -v -r 0-6 localhost:3000And the first 6 bytes of index.html will be delivered.
Multipart ranges are not currently supported.
Multipart ranges are memory hogs and difficult to deliver efficiently without abusing memory resources.
File_server is released under the BSD 3-Clause License.