Permalink
Browse files

Cleaned up a bit, still doesn't work.

  • Loading branch information...
1 parent 92d8f3d commit ddd8612488418ac011d2c917a09882bb7d5ab42e @supernovus committed Feb 27, 2010
Showing with 34 additions and 5 deletions.
  1. +15 −0 SCGI-test.p6
  2. +15 −5 SCGI.pm
  3. +4 −0 TODO
View
@@ -0,0 +1,15 @@
+#!/usr/local/bin/perl6
+
+#BEGIN { @*INC.push: './lib'; }
+
+use SCGI;
+
+my $scgi = SCGI.new();
+
+my $handler = sub (%env) {
+ my $name = %env<QUERY_STRING> // 'World';
+ return "Content-type: text/plain\n\nHello $name\n";
+}
+
+$scgi.handle: $handler;
+
View
20 SCGI.pm
@@ -61,11 +61,17 @@ class SCGI::Request {
my %env = $env_string.split("\0");
die "malformed or missing CONTENT_LENGTH header" unless %env<CONTENT_LENGTH> && %env<CONTENT_LENGTH> ~~ / ^ \d+ $ /;
die "missing SCGI header" unless %env<SCGI> && %env<SCGI> eq '1';
- my $body = $.connection.recv(%env<CONTENT_LENGTH>);
- %env<Request.Body> = $body;
%.env = %env;
}
+ method read_body {
+ my $body;
+ if %.env<CONTENT_LENGTH> {
+ $body = $.connection.recv(%.env<CONTENT_LENGTH>);
+ }
+ return $body;
+ }
+
submethod DESTROY {
self.close unless $.closed;
}
@@ -80,6 +86,9 @@ class SCGI {
has IO::Socket $.socket = IO::Socket::INET.socket(2, 1, 6)\
.bind($!addr, $!port)\
.listen();
+ has $!bodykey = 'Request.Body';
+ has $!requestkey = 'Request.Object';
+ has $!scgikey = 'Request.SCGI';
method accept () {
my $connection = self.socket.accept() or return;
@@ -91,9 +100,10 @@ class SCGI {
while (my $request = self.accept) {
$request.read_env;
my %env = $request.env;
- %env<Request.Object> = $request;
- %env<Request.SCGI> = self;
- closure(%env);
+ %env($!requestkey) = $request;
+ %env($!scgikey) = self;
+ %env($!bodykey) = $request.read_body;
+ $request.connection.send($.closure(%env));
}
}
View
4 TODO
@@ -1,2 +1,6 @@
- Fix the library. In the January release of Rakudo, it bails out
when you try to open a connection to the port.
+ - I may end up changing how SCGI::Request reads from the socket.
+ Reading the entire request, then parsing the components may be
+ a simpler method. We'll see.
+

0 comments on commit ddd8612

Please sign in to comment.