Permalink
Browse files

Now uses HTTP::Status

  • Loading branch information...
supernovus committed Sep 30, 2011
1 parent 5e14539 commit 634d120ef221590ced9c22797385aa58aa45401e
Showing with 35 additions and 17 deletions.
  1. +1 −1 META.info
  2. +23 −9 README
  3. +1 −1 TODO
  4. +1 −1 { → examples}/test.p6
  5. +9 −5 lib/HTTP/Easy/PSGI.pm6
View
@@ -2,6 +2,6 @@
"name" : "HTTP::Easy",
"version" : "*",
"description" : "HTTP servers made easy, including PSGI",
- "depends" : [ ],
+ "depends" : [ "HTTP::Status" ],
"source-url" : "git://github.com/supernovus/perl6-http-easy.git"
}
View
32 README
@@ -1,32 +1,45 @@
HTTP::Easy
-----------
-Perl 6 libraries to make HTTP servers easily. Inspired by HTTP::Server::Simple.
-Eventually this will also include HTTP::Easy::Client but that's not high priority right now.
+Perl 6 libraries to make HTTP servers easily.
+
+This was inspired by HTTP::Server::Simple, but has a very different internal
+API, and extended functionality. It's been designed to work well with my
+own WWW::App and SCGI libraries. Also see my HTTP::Client library if you
+are looking for an HTTP client rather than an HTTP server.
= HTTP::Easy =
-A role to build custom HTTP servers. Provides the framework for parsing HTTP connections.
-The classes implementing this must provide the rest, and send the appropriate output.
+A role to build custom HTTP servers.
+Provides the framework for parsing HTTP connections.
+The classes implementing this must provide the rest, and send the appropriate
+output (in HTTP compliant ways.)
= HTTP::Easy::PSGI =
-A class implementing HTTP::Easy. This builds a PSGI environment, and passes it onto
-a handler. The handler must return a PSGI response (e.g.: [ $status, @headers, @body ] )
+A class implementing HTTP::Easy. This builds a PSGI environment, and passes
+it onto a handler. The handler must return a PSGI response
+(e.g.: [ $status, @headers, @body ] )
+
This can be used as an engine in the WWW::App library.
= HTTP::Easy::SCGI =
** Not implemented yet, see TODO **
-A class implementing HTTP::Easy. This uses SCGI::Client to send a request to an SCGI daemon.
-It will receive the reply from the SCGI daemon, and parse it accordingly (it automatically
-detects if NPH output was returned.)
+A class implementing HTTP::Easy. This connects to an SCGI daemon.
+It will receive the reply from the SCGI daemon, and parse it accordingly
+(it automatically detects if NPH output was returned.)
= Examples =
See the examples in the 'examples/' folder.
+= Requirements =
+
+ * Rakudo Perl 6
+ * HTTP::Status
+
= Author =
Timothy Totten
@@ -36,3 +49,4 @@ http://github.com/supernovus/
= License =
Artistic License 2.0
+
View
2 TODO
@@ -1,2 +1,2 @@
-* Add HTTP::Easy::SCGI (and corresponding SCGI::Client)
+* Add HTTP::Easy::SCGI
* Add examples other than test.p6
@@ -1,6 +1,6 @@
#!/usr/bin/env perl6
-BEGIN { @*INC.push: './lib'; }
+BEGIN { @*INC.unshift: './lib'; }
use HTTP::Easy::PSGI;
View
@@ -5,8 +5,11 @@ use HTTP::Easy;
class HTTP::Easy::PSGI is HTTP::Easy;
+use HTTP::Status;
+
+constant $CRLF = "\x0D\x0A";
+
has $!app is rw;
-has $!crlf = "\x0D\x0A";
method app ($app) {
$!app = $app;
@@ -33,12 +36,13 @@ method handler {
else {
die "Invalid {self.WHAT} application.";
}
- my $output = %.env<SERVER_PROTOCOL>~' '~$result[0]~$!crlf;
+ my $message = get_http_status_msg($result[0]);
+ my $output = %.env<SERVER_PROTOCOL>~' '~$result[0]~" $message$CRLF";
for @($result[1]) -> $header {
- $output ~= $header.key ~ ': ' ~ $header.value ~ $!crlf;
+ $output ~= $header.key ~ ': ' ~ $header.value ~ $CRLF;
}
- my $body = $result[2].join($!crlf);
- $output ~= $!crlf ~ $body;
+ my $body = $result[2].join($CRLF);
+ $output ~= $CRLF ~ $body;
return $output;
}

0 comments on commit 634d120

Please sign in to comment.