[Haskell-cafe] Network.CGI.Compat.pwrapper

Albert Y. C. Lai trebla at vex.net
Mon Feb 12 17:27:29 EST 2007

Bjorn Bringert wrote:
> pwrapper is not an HTTP server, though the Haddock comment can make you 
> think so. pwrapper allows you to talk *CGI* over a TCP port, but I have 
> no idea why anyone would like to do that.

Here is a scenerio. I want a basic web application: someone makes a 
request, and my program computes a response.

* For one reason or another, I settle with CGI.

* The program is huge and slow to load. (Let's say it statically links 
in the whole GHC API and therefore is basically GHC itself. :) ) It 
would suck to re-load this program at every request.

* Or, the program performs work that requires more file-system privilege 
than the admin of the web server grants. You know, a good admin sets up 
a web server and all CGI scripts to run with nobody's privilege.

* Or, nevermind performance or privilege. I am a cheapo, and I use a 
cheapo hosting provider, which only provides me with 3MB of storage. My 
program weighs 17MB (recall that it links in the whole GHC :) ).

Here is a solution. The program runs as a daemon and never quits; it can 
run somewhere with sufficient privilege and storage. It talks CGI over 
TCP. At the web server, which is super-slow, super-paranoid, and 
super-cheapo, the CGI script is a lightweight C program that redirects 
everything over TCP to my daemon.

(Here is a counter-solution. The program still runs as a daemon 
somewhere, but it talks my own protocol over TCP. The CGI script is a 
lightweight C program that parses CGI into my own protocol. Besides 
having to design my own protocol carefully, here is a problem: C is a 
great language for writing parsers that are incomplete, inconsistent, 
and insecure. :) )

More information about the Haskell-Cafe mailing list