vintage
Let's take it back to the 1990s. This library implements a multi-threaded server that speaks the FastCGI protocol.
[!WARNING] Still a work in progress.
[!NOTE] Useful terminology:
- CGI: A specification HTTP web servers can follow to execute a program in response to HTTP requests. For example, you would configure your web server (e.g. Apache) to execute a certain bash script when a request came in. The bash script would get access to request metadata via environment variables.
- FastCGI: A successor to CGI (Common Gateway Interface). Unlike CGI, programs are not executed every time a request comes in. Instead, a FastCGI application is started and listens on a socket, and the HTTP web server communicates HTTP request metadata via that socket. The FastCGI spec is a definition of the binary protocol used to communicate on that socket.
- FastCGI client: The program that initiates a FastCGI connection. In most cases, this is the HTTP web server; it receives an HTTP request from a browser, and forwards that request to the FastCGI server.
- FastCGI server: A program that listens on a socket, and responds to requests from a FastCGI client.
Try it out!
Browsers don't speak FastCGI protocol. Thankfully, most popular web servers do. So to test locally, we'll have to have one such web server running. I'll be using Nginx & Caddy as examples. Pick one.
- Download either Nginx or Caddy
- Configure the web server to reverse proxy fastcgi:
-
If you picked caddy, stick this in a file in the current directory called
Caddyfile:localhost { reverse_proxy localhost:8000 { transport fastcgi } } -
If you picked nginx, stick this in a file in the current directory called
nginx.conf:events { } http { server { location / { fastcgi_pass localhost:8000; } } }
-
- Run the web server
- Caddy:
sudo caddy run --config Caddyfile - Nginx:
sudo nginx -p $(pwd) -c nginx.conf
- Caddy:
- Run
cargo new --bin app && cd app && cargo add vintage, and stick this inmain.rs:use ; - Run
cargo run - Visit
http://localhoston your browser!
Why?
- I've been waiting for an excuse to use thread pools.
- The common setup of having an HTTP Web Server like nginx or caddy reverse-proxying to another internal HTTP server feels a bit silly: Why are there two programs re-parsing HTTP?
- To rage against the rust async server monoculture and pave my own way ✊.
Similar libraries
[^1]: The only solid one I know of is rouille but that has not been updated in a while, and now has compilation warnings, which don't spark joy :/ Yes, those compilation warnings are the only reason I sought an alternative.