Common Gateway Interface
Yesterday I’ve been reading through CGI specs to figure how it works. CGI is the most simple way to test FOW core parts - you just make a standalone binary and feed it with “webserver-like” data. With some luck you can even make unit testing work.
The most simple case are GET requests. They are just passed via QUERY_STRING environment variable. In fact, all server headers are passed in through environment.
Now, POST requests. Basic stuff is pretty similar. You get CONTENT_TYPE (something like “application/x-www-form-urlencoded”) and HTTP_CONTENT_LENGTH, then just read HTTP_CONTENT_LENGTH bytes from stdin and parse them same way as you do with GET stuff.
Things are getting tricky when you need to send some complex data (read: upload file) via POST. First of all, your new content type is “multipart/form-data” followed by boundary specifier. Stdin is treated as chunks of binary data delimited by boundary specifier with additional headers (those include Content-Disposition and Content-Type). After that you have an ‘\n’ and binary data.