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)
head
requestsrange
requests- encoded requests
Bash the following commands:
git clone https://github.com/herebythere/file_server
cargo install --path file_server/file_server
Bash the following command:
file_server
This will start file_server
with it's default configuration in the cwd
.
Now files can be requested from the cwd
at localhost:3000
:
curl localhost:3000
A valid JSON configuration file matches the following schema.
{
"directory": "./demo",
"host_and_port": "127.0.0.1:4000",
"content_encodings": ["gzip", "deflate", "br", "zstd"],
"filepath_404": "./demo/404.html"
}
Filepaths can be relative or absolute. Relative paths are "relative from" the filepath of the JSON configuration.
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.json
Open a browser and visit http://localhost:3000
and an encoded version of index.html
will be delivered.
When an accept-encoding
header is found in a request, 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 source file has a correspponding gziped file:
index.html # source file
index.html.gz # gzipped file
File_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:3000
And 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.