Skip to content

w-lfpup/file_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

file_server

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 requests
  • range requests
  • encoded requests

How to use

Install

Bash the following commands:

git clone https://github.com/herebythere/file_server
cargo install --path file_server/file_server

Run

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

Configuration

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.

Run with configuration

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.

Accept-Encoding

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.

No dynamic encoding support

File_server does not encode or zip files ever.

This program serves static files. Just zip them up now to save memory resources.

Range requests

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.

License

File_server is released under the BSD 3-Clause License.

About

a file server and companion library in rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages