Common Gateway Interface

By farcaller May 27th, 2008

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.


					

Tags:

This entry was posted on Tuesday, May 27th, 2008 at 14:50 and is filed under Prototyping. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply