Skip to content

huynguyenvu1996/tiny-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Tiny HTTP Server

Lightweight HTTP server that loads a ZIP archive into RAM (using miniz) and serves files directly from memory (Source code assisted by ChatGPT 😄).

Features

  • Serves static files from a ZIP archive loaded into RAM.
  • SPA fallback: unknown paths fall back to /index.html.
  • Simple health endpoint at /health.
  • Small, static binary (build with musl-gcc and optional upx).

Requirements

  • musl-gcc (or a compatible C compiler and static linking toolchain)
  • POSIX-compatible environment for networking and signals

Files

  • tiny_http_server.c — server source
  • miniz.h miniz.c — miniz ZIP handling
  • Resulting binary: tiny-http-server

Build

Run the same command used in the source header:

musl-gcc -Os -static -s  -fdata-sections -ffunction-sections -Wl,--gc-sections tiny_http_server.c  miniz.c  -o tiny-http-server
strip --strip-all tiny-http-server
upx --best --lzma tiny-http-server    # optional

Run

Start the server with:

./tiny-http-server <port> <zipfile>

For healthcheck mode:

./tiny-http-server --healthcheck <port> <zipfile>

Example:

./tiny-http-server 8000 assets.zip
./tiny-http-server --healthcheck 8000 assets.zip

Endpoints

  • /<path> — serves the file with that path inside the ZIP (ZIP filenames must not start with /)
  • / — served as /index.html
  • /health — returns OK for health checks

Zip format notes

  • Filenames in the ZIP should match requested paths without a leading slash. E.g. request /css/app.css should exist in ZIP as css/app.css.
  • SPA fallback: if a path is not found, the server tries /index.html.

Limits & behavior

  • Maximum files: MAX_FILES (128 by default)
  • Maximum file size: MAX_FILE_SIZE (~1.2 MB by default). Files larger than this are skipped.
  • Files are stored in static memory buffers; adjust constants in tiny_http_server.c if needed.
  • No directory traversal normalization; requests are matched exactly against ZIP entry names (minus the leading /).

Signals & shutdown

  • Handles SIGTERM for graceful shutdown. SIGINT (Ctrl+C) will terminate the process normally.

Security & caveats

  • Minimal HTTP/1.0 implementation — no chunked encoding, no persistent connections, basic header handling.
  • Not intended for untrusted environments or production without audit.
  • Be mindful of ZIP contents and sizes to avoid memory issues.

License

MIT

Third-Party Licenses

This project includes third-party components licensed:

  • miniz
    • Copyright 2013-2014 RAD Game Tools and Valve Software
    • Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
    • See third_party_licenses/miniz_LICENSE for details.

About

Tiny HTTP Server

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages