Skip to content

br0kenpixel/leafhttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeafHttp Web Server

LeafHttp is a simple configurable web server.

⚠️ This project is for demo/educational purposes! It is *NOT* designed for production use.

Features

  • Configurable IP/Port binding
  • Configurable WWW directory
  • Optional path traversal protection
  • Connection limiter
  • Can serve simple HTML/JS/CSS/etc. files
  • ⚠️ PHP is not supported (will be served as plain text)!
  • POST handling 🛠

Compatibility

  • ✅ Linux
  • ✅ macOS
  • ❌ Windows
    • Not supported due to home_dir using POSIX APIs.
    • This may be fixed in the future.

Limitations/Notes

  • The server strictly expects that requests are separated by \r\n. Using two newlines will cause parse errors (and thus 501s).
  • Clients are handled on separate threads, so don't make max-connections too high (unless you have a ton of CPU cores).
  • Only GET requests are supported.
  • max-request-size counts the entire request, not just the body.
  • The request body must contain valid UTF-8 characters. The server will respond with a 501 if you send a body with non-UTF-8 characters.

Client handling

Every client is handled in a separate thread. When the connection limit is reached, the socket is immediately closed.

Configuration

See default_config.yml.

Cross-compiling

Since home_dir depends on nix, you may get some linker errors.

If you get an error like ld: unknown option: --as-needed (especially on macOS), you can fix it by changing the linker. This can be done by creating a .cargo/config.toml config file, and specifying the following overrides:

[target.x86_64-unknown-linux-gnu] # macOS -> x86 Linux
linker = "x86_64-unknown-linux-gnu-gcc"

You'll need to adjust this to your needs.