Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (63 sloc) 2.847 kB
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
1 SCGI for Perl 6
2 -----------------
3
4 This is a simple SCGI library for Perl 6.
5
6 It's main influences are the Perl 5 SCGI library, and the
7 Perl 6 HTTP::Daemon library.
8
9 It offers a bit of candy coating compared to the Perl 5 version.
10
7b86ab9 @supernovus Debugging made explicit. Added PSGI mode, and a test for it.
authored
11 It also offers an optional (but recommended) PSGI interface.
12
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
13 The environment contains three special keys:
14
7b86ab9 @supernovus Debugging made explicit. Added PSGI mode, and a test for it.
authored
15 SCGI.Body is the request body (usually from an HTTP POST.)
16 SCGI.Object is a reference to the individual request object.
17 SCGI.SCGI is a reference to the SCGI object itself.
18
19 If you use the PSGI setting, the standard PSGI variables will be added
20 to the environment too.
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
21
22 Also, you don't need to create your own IO::Socket::INET object.
23 Just pass an 'addr' and 'port' attribute to the new() declaration and it'll
24 create the object for you.
25
26 Oh yeah, and instead of using the while loop as shown on the Perl 5 SCGI
27 documentation, there is a convenience method called 'handle' that does
28 the heavy lifting for you:
29
30
92d8f3d @supernovus Fixed code example in README.
authored
31 use SCGI;
32
7b86ab9 @supernovus Debugging made explicit. Added PSGI mode, and a test for it.
authored
33 my $scgi = SCGI.new( :addr<localhost>, :port(8080), :PSGI );
92d8f3d @supernovus Fixed code example in README.
authored
34
35 my $handler = sub (%env) {
36 my $name = %env<QUERY_STRING> // 'world';
7b86ab9 @supernovus Debugging made explicit. Added PSGI mode, and a test for it.
authored
37 my $status = '200';
38 my @headers = [ 'Content-Type' => 'text/plain' ];
39 my @body = [ "Hello $name\n" ];
40 return [ $status, @headers, @body ];
92d8f3d @supernovus Fixed code example in README.
authored
41 }
42
43 $scgi.handle: $handler;
44
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
45
7b86ab9 @supernovus Debugging made explicit. Added PSGI mode, and a test for it.
authored
46 If you are not using the PSGI interface, the output of the handler will be
47 sent as the SCGI response, so make sure it is a valid CGI response!
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
48
de4c3cc @supernovus Added notes for using mod_proxy_scgi
authored
49 ** Apache configuration:
50
51 *** If using mod_scgi:
00d06c0 @supernovus Added Apache config info, and shutdown method.
authored
52
53 Add the following line to your site config, changing the details to match your
54 SCGI script configuration:
55
56 SCGIMount /scgi/ 127.0.0.1:8118
57
de4c3cc @supernovus Added notes for using mod_proxy_scgi
authored
58 *** If using mod_proxy_scgi:
59
60 Add the following line to your site config, changes the details to match your
61 SCGI script configuration:
62
63 <Proxy *>
64 Order deny,allow
65 Allow from all
66 </Proxy>
67 ProxyPass /scgi/ scgi://localhost:8118/
68
69 *** Apache redirect rules
70
71 Regardless of whether you are using mod_scgi or mod_proxy_scgi, you can
72 use the following steps to redirect non-exitent pages to your SCGI script.
73
74 Add the following lines either after the above statement, or in an
00d06c0 @supernovus Added Apache config info, and shutdown method.
authored
75 .htaccess file in your website root:
76
77 RewriteEngine On
78
79 ## Add additional rules before the following!
80 RewriteCond %{REQUEST_FILENAME} !-f
81 RewriteRule ^(.*)$ /scgi/$1 [QSA,L,PT]
82
83 That's it. Now any path that doesn't match an existing file in your
84 web root, will be redirected to your SCGI script.
85
86 Similar tricks are available for other web servers, but I haven't tested
87 them, so have not documented them. A quick Google search for SCGI should
88 turn up a multitude of howto documents.
89
00640f7 @supernovus Now uses HTTP::Status
authored
90 ** Requirements:
91
92 * Rakudo Perl 6 <http://rakudo.org/>
93 * HTTP::Status <http://github.com/supernovus/perl6-http-status/>
94
1f43c02 Initial release as standalone project.
Timothy M. Totten authored
95 Author: Timothy Totten (supernovus) <2010@huri.net> http://huri.net/
96
97 Released under the Artisitc License 2.0
b73aebe @supernovus Rewrote the Request parsing. Refactored the rest.
authored
98
Something went wrong with that request. Please try again.