Out of curiosity, I looked at the PSGI/Plack website and made an amusing discovery.
Many years ago, before I "discovered" Perl, I wrote a webserver in AWK. It wasn't purely in AWK; I wrote a C program to listen for and accept incoming HTTP connections. It then read the request and "parsed" it into an array of name/value pairs, then exec'd AWK, using the array as the environment pointer.
Seems I "invented" "ASGI". Not the same as PSGI, but very close.
| [reply] |
| [reply] |
Maybe. The USB "stick" that had the back up copy is long lost, though the PC it ran is still gathering dust. Hasn't been powered for over 10 years, so I have no idea if the hard disk or any of it will function any more.
The C program was a basic TCP server with a while loop to accept a connection, fork, read the HTTP header line-by-line, slurp the content (Perl equiv: sysread($connection, $buffer, $contentlength)), use strchr(buffer, '\r') to break the content (which was assumed to be "application/x-www-form-urlencoded") into "key=value" pairs and build an array of pointers (the HTTP headers were also included in the array). Then it would
execle(awkint, awkint, awkscript, NULL, array).
The AWK script would then access the HTTP and form fields as environment variables, doing url-decode as needed, process the request and generate the response, including the HTTP headers, streaming it out STDOUT.
This wasn't hard, just very tedious. My co-workers dubbed me "The Wizard of AWK".
Then I "discovered" Perl.
| [reply] [d/l] [select] |
Here is an example of using Plack to capture form queries:
use Data::Dumper;
use Plack::Request;
use Plack::Response;
my $app = sub {
my $req = Plack::Request->new(shift);
my $query = $req->parameters;
my $res = Plack::Response->new(200);
$res->body('<pre>' . Dumper($query) . '</pre>');
$res->finalize;
};
| [reply] [d/l] |