Basic-http-server, a simple HTTP file server built on Rotor

While working on the docs I wanted to be able to serve them quickly, but didn't have a Rust-based tool for it, so I wrote basic-http-server as an excuse to play with rotor. It serves static files out of the current directory over HTTP.

Here is it's --help output.

USAGE:
        basic-http-server [FLAGS] [OPTIONS] [ARGS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -a, --addr <ADDR>    Sets the IP:PORT combination (default "127.0.0.1:4000")

ARGS:
    ROOT    Sets the root dir (default ".")

The source is simple and thoroughly commented.

I've had difficulty measuring how fast it is. When I measure with wrk the results seem good, but with ab all requests timeout. I suspect that's a bug in rotor-http, but don't know.

cc @tailhook

4 Likes

I've had difficulty measuring how fast it is. When I measure with wrk the results seem good, but with ab all requests timeout. I suspect that's a bug in rotor-http, but don't know.

Yes, this is a known thing. The ab sends requests with Connection: close and expects the connection to be closed when a request is done, regardless of the Content-Length and Transfer-Encoding headers. Most other tools and browsers are smart enough to respect Content-Length, so proper handling of Connection: close is hanging on my todo list.

While it's probably easy enough to fix, I'm working on client implementation of HTTP, and I hope to refactor connection state machine a little bit to reuse it for client protocol too (however, I'm not sure it's a great idea yet).

By the way, should I release current versions of rotor stuff on crates.io, so that basic-http-server could be installed by cargo install ? This might be good enough replacement for webfs or devd for some cases.

I'm not in any hurry, but yeah, I would like to publish it on crates.io.

@brson this is great! I'll prefer this over python's SimpleHTTPServer in the future :smile:

I've published this to crates.io, so now it can be installed with cargo install basic-http-server.