Skip to content
This repository
Browse code

removed Mojo::Server::FastCGI so it can be maintained as a separe dis…

…tribution
  • Loading branch information...
commit a1a16bb1ccdadb84d2b4942ff79db15a7db17260 1 parent 0fc549c
Sebastian Riedel authored
2  Changes
... ... @@ -1,6 +1,8 @@
1 1 This file documents the revision history for Perl extension Mojolicious.
2 2
3 3 1.98 2011-09-11 00:00:00
  4 + - Removed Mojo::Server::FastCGI so it can be maintained as a separate
  5 + distribution.
4 6 - Added EXPERIMENTAL mojo_lib_dir and slurp_rel_file methods to
5 7 Mojo::Home.
6 8 - Improved host condition to work in more environments.
2  README.pod
Source Rendered
@@ -45,7 +45,7 @@ perfect for embedding.
45 45
46 46 =item *
47 47
48   -Automatic CGI, FastCGI and L<PSGI> detection.
  48 +Automatic CGI and L<PSGI> detection.
49 49
50 50 =item *
51 51
4 lib/Mojo.pm
@@ -55,8 +55,8 @@ Mojo - The Duct Tape!
55 55
56 56 use Mojo::Base 'Mojo';
57 57
58   - # All the complexities of CGI, FastCGI, PSGI, HTTP and WebSockets get
59   - # reduced to a single method call!
  58 + # All the complexities of CGI, PSGI, HTTP and WebSockets get reduced to a
  59 + # single method call!
60 60 sub handler {
61 61 my ($self, $tx) = @_;
62 62
14 lib/Mojo/Command.pm
@@ -20,8 +20,8 @@ has description => 'No description.';
20 20 has message => <<"EOF";
21 21 usage: $0 COMMAND [OPTIONS]
22 22
23   -Tip: CGI, FastCGI and PSGI environments can be automatically detected very
24   - often and work without commands.
  23 +Tip: CGI and PSGI environments can be automatically detected very often and
  24 + work without commands.
25 25
26 26 These commands are currently available:
27 27 EOF
@@ -94,16 +94,8 @@ sub detect {
94 94 return 'cgi'
95 95 if defined $ENV{PATH_INFO} || defined $ENV{GATEWAY_INTERFACE};
96 96
97   - # No further detection if we have a guess
98   - return $guess if $guess;
99   -
100   - # FastCGI (detect absence of WINDIR for Windows and USER for UNIX)
101   - return 'fastcgi'
102   - if !defined $ENV{WINDIR}
103   - && !defined $ENV{USER}
104   - && !defined $ENV{HARNESS_ACTIVE};
105   -
106 97 # Nothing
  98 + return $guess if $guess;
107 99 return;
108 100 }
109 101
506 lib/Mojo/Server/FastCGI.pm
... ... @@ -1,506 +0,0 @@
1   -package Mojo::Server::FastCGI;
2   -use Mojo::Base 'Mojo::Server';
3   -
4   -use Errno qw/EAGAIN EINTR EWOULDBLOCK/;
5   -use IO::Socket;
6   -
7   -use constant DEBUG => $ENV{MOJO_FASTCGI_DEBUG} || 0;
8   -
9   -# Roles
10   -my @ROLES = qw/RESPONDER AUTHORIZER FILTER/;
11   -my %ROLE_NUMBERS;
12   -{
13   - my $i = 1;
14   - for my $role (@ROLES) {
15   - $ROLE_NUMBERS{$role} = $i;
16   - $i++;
17   - }
18   -}
19   -
20   -# Types
21   -my @TYPES = qw/
22   - BEGIN_REQUEST
23   - ABORT_REQUEST
24   - END_REQUEST
25   - PARAMS
26   - STDIN
27   - STDOUT
28   - STDERR
29   - DATA
30   - GET_VALUES
31   - GET_VALUES_RESULT
32   - UNKNOWN_TYPE
33   - /;
34   -my %TYPE_NUMBERS;
35   -{
36   - my $i = 1;
37   - for my $type (@TYPES) {
38   - $TYPE_NUMBERS{$type} = $i;
39   - $i++;
40   - }
41   -}
42   -
43   -# "Wow! Homer must have got one of those robot cars!
44   -# *Car crashes in background*
45   -# Yeah, one of those AMERICAN robot cars."
46   -sub accept_connection {
47   - my $self = shift;
48   -
49   - # Listen socket
50   - unless ($self->{listen}) {
51   - my $listen = IO::Socket->new;
52   -
53   - # Open
54   - unless ($listen->fdopen(0, 'r')) {
55   - $self->app->log->error("Can't open FastCGI socket fd0: $!");
56   - return;
57   - }
58   -
59   - $self->{listen} = $listen;
60   - }
61   - $self->app->log->debug('FastCGI listen socket opened.') if DEBUG;
62   -
63   - # Accept
64   - my $c;
65   - unless ($c = $self->{listen}->accept) {
66   - $self->app->log->error("Can't accept FastCGI connection: $!");
67   - return;
68   - }
69   - $self->app->log->debug('Accepted FastCGI connection.') if DEBUG;
70   -
71   - return $c;
72   -}
73   -
74   -sub read_record {
75   - my ($self, $c) = @_;
76   - return unless $c;
77   -
78   - # Header
79   - my $header = $self->_read_chunk($c, 8);
80   - return unless $header;
81   - my ($version, $type, $id, $clen, $plen) = unpack 'CCnnC', $header;
82   -
83   - # Body
84   - my $body = $self->_read_chunk($c, $clen + $plen);
85   -
86   - # No content, just paddign bytes
87   - $body = undef unless $clen;
88   -
89   - # Ignore padding bytes
90   - $body = $plen ? substr($body, 0, $clen, '') : $body;
91   -
92   - if (DEBUG) {
93   - my $t = $self->type_name($type);
94   - $self->app->log->debug(
95   - qq/Reading FastCGI record: $type - $id - "$body"./);
96   - }
97   -
98   - return $self->type_name($type), $id, $body;
99   -}
100   -
101   -sub read_request {
102   - my ($self, $c) = @_;
103   - $self->app->log->debug('Reading FastCGI request.') if DEBUG;
104   -
105   - # Transaction
106   - my $tx = $self->on_transaction->($self);
107   - $tx->connection($c);
108   - my $req = $tx->req;
109   -
110   - # Type
111   - my ($type, $id, $body) = $self->read_record($c);
112   - unless ($type && $type eq 'BEGIN_REQUEST') {
113   - $self->app->log->error("First FastCGI record wasn't a begin request.");
114   - return;
115   - }
116   - $ENV{FCGI_ID} = $tx->{fcgi_id} = $id;
117   -
118   - # Role/Flags
119   - my ($role, $flags) = unpack 'nC', $body;
120   - $ENV{FCGI_ROLE} = $tx->{fcgi_role} = $self->role_name($role);
121   -
122   - # Slurp
123   - my $buffer = '';
124   - my $env = {};
125   - while (($type, $id, $body) = $self->read_record($c)) {
126   -
127   - # Wrong id
128   - next unless $id == $tx->{fcgi_id};
129   -
130   - # Params
131   - if ($type eq 'PARAMS') {
132   -
133   - # Normal param chunk
134   - if ($body) {
135   - $buffer .= $body;
136   - next;
137   - }
138   -
139   - # Params done
140   - while (length $buffer) {
141   -
142   - # Name and value length
143   - my $name_len = $self->_nv_length(\$buffer);
144   - my $value_len = $self->_nv_length(\$buffer);
145   -
146   - # Name and value
147   - my $name = substr $buffer, 0, $name_len, '';
148   - my $value = substr $buffer, 0, $value_len, '';
149   -
150   - # Environment
151   - $env->{$name} = $value;
152   - $self->app->log->debug(qq/FastCGI param: $name - "$value"./)
153   - if DEBUG;
154   -
155   - # Store connection information
156   - $tx->remote_address($value) if $name =~ /REMOTE_ADDR/i;
157   - $tx->local_port($value) if $name =~ /SERVER_PORT/i;
158   - }
159   - }
160   -
161   - # Stdin
162   - elsif ($type eq 'STDIN') {
163   -
164   - # Environment
165   - if (keys %$env) {
166   - $req->parse($env);
167   - $env = {};
168   - }
169   -
170   - # EOF
171   - last unless $body;
172   -
173   - # Chunk
174   - $req->parse($body);
175   -
176   - # Error
177   - return $tx if $req->error;
178   - }
179   - }
180   -
181   - return $tx;
182   -}
183   -
184   -sub role_name {
185   - my ($self, $role) = @_;
186   - return unless $role;
187   - return $ROLES[$role - 1];
188   -}
189   -
190   -sub role_number {
191   - my ($self, $role) = @_;
192   - return unless $role;
193   - return $ROLE_NUMBERS{uc $role};
194   -}
195   -
196   -sub run {
197   - my $self = shift;
198   -
199   - # Preload application
200   - $self->app;
201   -
202   - # New incoming request
203   - while (my $c = $self->accept_connection) {
204   -
205   - # Request
206   - my $tx = $self->read_request($c);
207   -
208   - # Error
209   - unless ($tx) {
210   - $self->app->log->error("No transaction for FastCGI request.");
211   - next;
212   - }
213   -
214   - # Handle
215   - $self->app->log->debug('Handling FastCGI request.') if DEBUG;
216   - $self->on_request->($self, $tx);
217   -
218   - # Response
219   - $self->write_response($tx);
220   -
221   - # Finish transaction
222   - $tx->on_finish->($tx);
223   - }
224   -}
225   -
226   -sub type_name {
227   - my ($self, $type) = @_;
228   - return unless $type;
229   - return $TYPES[$type - 1];
230   -}
231   -
232   -sub type_number {
233   - my ($self, $type) = @_;
234   - return unless $type;
235   - return $TYPE_NUMBERS{uc $type};
236   -}
237   -
238   -sub write_records {
239   - my ($self, $c, $type, $id, $body) = @_;
240   - return unless defined $c && defined $type && defined $id;
241   - $body ||= '';
242   -
243   - # Write records
244   - my $empty = $body ? 0 : 1;
245   - my $offset = 0;
246   - my $body_len = length $body;
247   - while (($body_len > 0) || $empty) {
248   -
249   - # Need to split content
250   - my $payload_len = $body_len > 32 * 1024 ? 32 * 1024 : $body_len;
251   - my $pad_len = (8 - ($payload_len % 8)) % 8;
252   -
253   - # FCGI version 1 record
254   - my $template = "CCnnCxa${payload_len}x$pad_len";
255   -
256   - if (DEBUG) {
257   - my $chunk = substr($body, $offset, $payload_len);
258   - $self->app->log->debug(
259   - qq/Writing FastCGI record: $type - $id - "$chunk"./);
260   - }
261   -
262   - # Write whole record
263   - my $record = pack $template, 1, $self->type_number($type), $id,
264   - $payload_len,
265   - $pad_len,
266   - substr($body, $offset, $payload_len);
267   - my $woffset = 0;
268   - while ($woffset < length $record) {
269   - my $written = $c->syswrite($record, undef, $woffset);
270   -
271   - # Error
272   - unless (defined $written) {
273   -
274   - # Retry
275   - next if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;
276   -
277   - # Write error
278   - return;
279   - }
280   -
281   - $woffset += $written;
282   - }
283   - $body_len -= $payload_len;
284   - $offset += $payload_len;
285   -
286   - # Done
287   - last if $empty;
288   - }
289   -
290   - return 1;
291   -}
292   -
293   -sub write_response {
294   - my ($self, $tx) = @_;
295   - $self->app->log->debug('Writing FastCGI response.') if DEBUG;
296   -
297   - # Status
298   - my $res = $tx->res;
299   - my $code = $res->code || 404;
300   - my $message = $res->message || $res->default_message;
301   - $res->headers->status("$code $message") unless $res->headers->status;
302   -
303   - # Fix headers
304   - $res->fix_headers;
305   -
306   - # Headers
307   - my $c = $tx->connection;
308   - my $offset = 0;
309   - while (1) {
310   - my $chunk = $res->get_header_chunk($offset);
311   -
312   - # No headers yet, try again
313   - unless (defined $chunk) {
314   - sleep 1;
315   - next;
316   - }
317   -
318   - # End of headers
319   - last unless length $chunk;
320   -
321   - # Headers
322   - $offset += length $chunk;
323   - return
324   - unless $self->write_records($c, 'STDOUT', $tx->{fcgi_id}, $chunk);
325   - }
326   -
327   - # Body
328   - $offset = 0;
329   - while (1) {
330   - my $chunk = $res->get_body_chunk($offset);
331   -
332   - # No content yet, try again
333   - unless (defined $chunk) {
334   - sleep 1;
335   - next;
336   - }
337   -
338   - # End of content
339   - last unless length $chunk;
340   -
341   - # Content
342   - $offset += length $chunk;
343   - return
344   - unless $self->write_records($c, 'STDOUT', $tx->{fcgi_id}, $chunk);
345   - }
346   -
347   - # The end
348   - return
349   - unless $self->write_records($c, 'STDOUT', $tx->{fcgi_id}, undef);
350   - return
351   - unless $self->write_records($c, 'END_REQUEST', $tx->{fcgi_id},
352   - pack('CCCCCCCC', 0));
353   -}
354   -
355   -sub _nv_length {
356   - my ($self, $bodyref) = @_;
357   -
358   - # Try first byte
359   - my $len = unpack 'C', substr($$bodyref, 0, 1, '');
360   -
361   - # 4 byte length
362   - if ($len & 0x80) {
363   - $len = pack 'C', $len & 0x7F;
364   - substr $len, 1, 0, substr($$bodyref, 0, 3, '');
365   - $len = unpack 'N', $len;
366   - }
367   -
368   - return $len;
369   -}
370   -
371   -sub _read_chunk {
372   - my ($self, $c, $len) = @_;
373   -
374   - # Read
375   - my $chunk = '';
376   - while (length $chunk < $len) {
377   - my $read = $c->sysread(my $buffer, $len - length $chunk, 0);
378   - unless (defined $read) {
379   - next if $! == EAGAIN || $! == EINTR || $! == EWOULDBLOCK;
380   - last;
381   - }
382   - last unless $read;
383   - $chunk .= $buffer;
384   - }
385   -
386   - return $chunk;
387   -}
388   -
389   -1;
390   -__END__
391   -
392   -=head1 NAME
393   -
394   -Mojo::Server::FastCGI - FastCGI Server
395   -
396   -=head1 SYNOPSIS
397   -
398   - use Mojo::Server::FastCGI;
399   -
400   - my $fcgi = Mojo::Server::FastCGI->new;
401   - $fcgi->on_request(sub {
402   - my ($self, $tx) = @_;
403   -
404   - # Request
405   - my $method = $tx->req->method;
406   - my $path = $tx->req->url->path;
407   -
408   - # Response
409   - $tx->res->code(200);
410   - $tx->res->headers->content_type('text/plain');
411   - $tx->res->body("$method request for $path!");
412   -
413   - # Resume transaction
414   - $tx->resume;
415   - });
416   - $fcgi->run;
417   -
418   -=head1 DESCRIPTION
419   -
420   -L<Mojo::Server::FastCGI> is a portable pure-Perl FastCGI implementation as
421   -described in the C<FastCGI Specification>.
422   -
423   -See L<Mojolicious::Guides::Cookbook> for deployment recipes.
424   -
425   -=head1 ATTRIBUTES
426   -
427   -L<Mojo::Server::FastCGI> inherits all attributes from L<Mojo::Server>.
428   -
429   -=head1 METHODS
430   -
431   -L<Mojo::Server::FastCGI> inherits all methods from L<Mojo::Server> and
432   -implements the following new ones.
433   -
434   -=head2 C<accept_connection>
435   -
436   - my $c = $fcgi->accept_connection;
437   -
438   -Accept FastCGI connection.
439   -
440   -=head2 C<read_record>
441   -
442   - my ($type, $id, $body) = $fcgi->read_record($c);
443   -
444   -Parse FastCGI record.
445   -
446   -=head2 C<read_request>
447   -
448   - my $tx = $fcgi->read_request($c);
449   -
450   -Parse FastCGI request.
451   -
452   -=head2 C<role_name>
453   -
454   - my $name = $fcgi->role_name(3);
455   -
456   -FastCGI role name.
457   -
458   -=head2 C<role_number>
459   -
460   - my $number = $fcgi->role_number('FILTER');
461   -
462   -FastCGI role number.
463   -
464   -=head2 C<run>
465   -
466   - $fcgi->run;
467   -
468   -Start FastCGI.
469   -
470   -=head2 C<type_name>
471   -
472   - my $name = $fcgi->type_name(5);
473   -
474   -FastCGI type name.
475   -
476   -=head2 C<type_number>
477   -
478   - my $number = $fcgi->type_number('STDIN');
479   -
480   -FastCGI type number.
481   -
482   -=head2 C<write_records>
483   -
484   - $fcgi->write_record($c, 'STDOUT', $id, 'HTTP/1.1 200 OK');
485   -
486   -Write FastCGI record.
487   -
488   -=head2 C<write_response>
489   -
490   - $fcgi->write_response($tx);
491   -
492   -Write FastCGI response.
493   -
494   -=head1 DEBUGGING
495   -
496   -You can set the C<MOJO_FASTCGI_DEBUG> environment variable to get some
497   -advanced diagnostics information sent to the L<Mojo> logger as C<debug>
498   -messages.
499   -
500   - MOJO_FASTCGI_DEBUG=1
501   -
502   -=head1 SEE ALSO
503   -
504   -L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
505   -
506   -=cut
3  lib/Mojo/Server/PSGI.pm
@@ -57,6 +57,9 @@ sub run {
57 57 return [$code, \@headers, $body];
58 58 }
59 59
  60 +# "Wow! Homer must have got one of those robot cars!
  61 +# *Car crashes in background*
  62 +# Yeah, one of those AMERICAN robot cars."
60 63 package Mojo::Server::PSGI::_Handle;
61 64 use Mojo::Base -base;
62 65
1  lib/Mojo/Util.pm
@@ -604,6 +604,7 @@ sub url_escape {
604 604 $_[0] =~ s/([^$pattern])/sprintf('%%%02X',ord($1))/ge;
605 605 }
606 606
  607 +# "I've gone back in time to when dinosaurs weren't just confined to zoos."
607 608 sub url_unescape {
608 609 return if index($_[0], '%') == -1;
609 610 $_[0] =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge;
21 lib/Mojolicious.pm
@@ -12,6 +12,7 @@ use Mojolicious::Static;
12 12 use Mojolicious::Types;
13 13 use Scalar::Util 'weaken';
14 14
  15 +# "Robots don't have any emotions, and sometimes that makes me very sad."
15 16 has controller_class => 'Mojolicious::Controller';
16 17 has mode => sub { ($ENV{MOJO_MODE} || 'development') };
17 18 has on_process => sub {
@@ -402,26 +403,6 @@ workflow.
402 403
403 404 Take a look at our excellent documentation in L<Mojolicious::Guides>!
404 405
405   -=head1 ARCHITECTURE
406   -
407   -Loosely coupled building blocks, use what you like and just ignore the rest.
408   -
409   - .---------------------------------------------------------------.
410   - | |
411   - | .----------------------------------------------'
412   - | | .--------------------------------------------.
413   - | Application | | Mojolicious::Lite |
414   - | | '--------------------------------------------'
415   - | | .--------------------------------------------.
416   - | | | Mojolicious |
417   - '----------------' '--------------------------------------------'
418   - .---------------------------------------------------------------.
419   - | Mojo |
420   - '---------------------------------------------------------------'
421   - .-------. .-----------. .--------. .------------. .-------------.
422   - | CGI | | FastCGI | | PSGI | | HTTP 1.1 | | WebSocket |
423   - '-------' '-----------' '--------' '------------' '-------------'
424   -
425 406 =head1 ATTRIBUTES
426 407
427 408 L<Mojolicious> inherits all attributes from L<Mojo> and implements the
69 lib/Mojolicious/Command/fastcgi.pm
... ... @@ -1,69 +0,0 @@
1   -package Mojolicious::Command::fastcgi;
2   -use Mojo::Base 'Mojo::Command';
3   -
4   -use Mojo::Server::FastCGI;
5   -
6   -has description => <<'EOF';
7   -Start application with FastCGI.
8   -EOF
9   -has usage => <<"EOF";
10   -usage: $0 fastcgi
11   -EOF
12   -
13   -# "Interesting... Oh no wait, the other thing, tedious."
14   -sub run { Mojo::Server::FastCGI->new->run }
15   -
16   -1;
17   -__END__
18   -
19   -=head1 NAME
20   -
21   -Mojolicious::Command::fastcgi - FastCGI Command
22   -
23   -=head1 SYNOPSIS
24   -
25   - use Mojolicious::Command::fastcgi;
26   -
27   - my $fastcgi = Mojolicious::Command::fastcgi->new;
28   - $fastcgi->run;
29   -
30   -=head1 DESCRIPTION
31   -
32   -L<Mojolicious::Command::fastcgi> is a command interface to
33   -L<Mojo::Server::FastCGI>.
34   -
35   -=head1 ATTRIBUTES
36   -
37   -L<Mojolicious::Command::FastCGI> inherits all attributes from
38   -L<Mojo::Command> and implements the following new ones.
39   -
40   -=head2 C<description>
41   -
42   - my $description = $fastcgi->description;
43   - $fastcgi = $fastcgi->description('Foo!');
44   -
45   -Short description of this command, used for the command list.
46   -
47   -=head2 C<usage>
48   -
49   - my $usage = $fastcgi->usage;
50   - $fastcgi = $fastcgi->usage('Foo!');
51   -
52   -Usage information for this command, used for the help screen.
53   -
54   -=head1 METHODS
55   -
56   -L<Mojolicious::Command::fastcgi> inherits all methods from L<Mojo::Command>
57   -and implements the following new ones.
58   -
59   -=head2 C<run>
60   -
61   - $fastcgi->run;
62   -
63   -Run this command.
64   -
65   -=head1 SEE ALSO
66   -
67   -L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
68   -
69   -=cut
7 lib/Mojolicious/Commands.pm
@@ -85,13 +85,6 @@ Start application with standalone HTTP 1.1 server backend.
85 85
86 86 Run code against application.
87 87
88   -=head2 C<fastcgi>
89   -
90   - $ mojo fastcgi
91   - $ script/myapp fastcgi
92   -
93   -Start application with FastCGI backend.
94   -
95 88 =head2 C<generate>
96 89
97 90 $ mojo generate
4 lib/Mojolicious/Guides.pod
Source Rendered
@@ -92,9 +92,9 @@ Full featured UNIX optimized preforking non-blocking I/O HTTP 1.1 and
92 92 WebSocket server with support for zero downtime software upgrades
93 93 (hot deployment).
94 94
95   -=item L<Mojo::Server::CGI>, L<Mojo::Server::FastCGI>, L<Mojo::Server::PSGI>
  95 +=item L<Mojo::Server::CGI>, L<Mojo::Server::PSGI>
96 96
97   -Transparent CGI, FastCGI and PSGI support out of the box.
  97 +Transparent CGI and PSGI support out of the box.
98 98
99 99 =item L<Mojo::Template>
100 100
10 lib/Mojolicious/Guides/Cookbook.pod
Source Rendered
@@ -120,16 +120,6 @@ automatically detect that it is executed as a C<CGI> script.
120 120
121 121 ScriptAlias / /home/sri/myapp/script/myapp/
122 122
123   -=head2 Apache/FastCGI
124   -
125   -C<FastCGI> is also supported out of the box and your L<Mojolicious>
126   -application will automatically detect that it is executed as a C<FastCGI>
127   -script.
128   -
129   - FastCgiIpcDir /home/sri/myapp
130   - FastCgiServer /home/sri/myapp/script/myapp -processes 1
131   - Alias / /home/sri/myapp/script/myapp/
132   -
133 123 =head2 PSGI/Plack
134 124
135 125 L<PSGI> is an interface between Perl web frameworks and web servers, and
7 lib/Mojolicious/Lite.pm
@@ -120,8 +120,8 @@ There is also a helper command to generate a small example application.
120 120 =head2 Commands
121 121
122 122 All the normal L<Mojolicious::Commands> are available from the command line.
123   -Note that CGI, FastCGI and PSGI environments can usually be auto detected and
124   -will just work without commands.
  123 +Note that CGI and PSGI environments can usually be auto detected and will
  124 +just work without commands.
125 125
126 126 $ ./myapp.pl daemon
127 127 Server available at http://127.0.0.1:3000.
@@ -132,9 +132,6 @@ will just work without commands.
132 132 $ ./myapp.pl cgi
133 133 ...CGI output...
134 134
135   - $ ./myapp.pl fastcgi
136   - ...Blocking FastCGI main loop...
137   -
138 135 $ ./myapp.pl
139 136 ...List of available commands (or automatically detected environment)...
140 137
1  lib/Mojolicious/Routes/Pattern.pm
@@ -200,6 +200,7 @@ sub _compile {
200 200 return $regex;
201 201 }
202 202
  203 +# "Interesting... Oh no wait, the other thing, tedious."
203 204 sub _compile_req {
204 205 my $req = shift;
205 206 return "($req)" if !ref $req || ref $req ne 'ARRAY';
126 t/mojo/apache_fastcgi.t
... ... @@ -1,126 +0,0 @@
1   -#!/usr/bin/env perl
2   -use Mojo::Base -strict;
3   -
4   -# Disable Bonjour, IPv6 and libev
5   -BEGIN {
6   - $ENV{MOJO_NO_BONJOUR} = $ENV{MOJO_NO_IPV6} = 1;
7   - $ENV{MOJO_IOWATCHER} = 'Mojo::IOWatcher';
8   -}
9   -
10   -# mod_fastcgi doesn't like small chunks
11   -BEGIN { $ENV{MOJO_CHUNK_SIZE} = 131072 }
12   -
13   -use Test::More;
14   -
15   -use File::Spec;
16   -use File::Temp;
17   -use IO::Socket::INET;
18   -use Mojo::IOLoop;
19   -use Mojo::Template;
20   -use Mojo::UserAgent;
21   -
22   -# Mac OS X only test
23   -plan skip_all => 'Mac OS X required for this test!' unless $^O eq 'darwin';
24   -plan skip_all => 'set TEST_APACHE to enable this test (developer only!)'
25   - unless $ENV{TEST_APACHE};
26   -plan tests => 12;
27   -
28   -# "Robots don't have any emotions, and sometimes that makes me very sad."
29   -use_ok 'Mojo::Server::FastCGI';
30   -
31   -# Setup
32   -my $port = Mojo::IOLoop->generate_port;
33   -my $dir = File::Temp::tempdir(CLEANUP => 1);
34   -my $config = File::Spec->catfile($dir, 'fcgi.config');
35   -my $mt = Mojo::Template->new;
36   -
37   -# FastCGI setup
38   -my $fcgi = File::Spec->catfile($dir, 'test.fcgi');
39   -$mt->render_to_file(<<'EOF', $fcgi);
40   -#!/usr/bin/env perl
41   -
42   -use strict;
43   -use warnings;
44   -
45   -% use FindBin;
46   -use lib '<%= "$FindBin::Bin/../../lib" %>';
47   -
48   -use Mojo::Server::FastCGI;
49   -
50   -Mojo::Server::FastCGI->new->run;
51   -
52   -1;
53   -EOF
54   -chmod 0777, $fcgi;
55   -ok -x $fcgi, 'script is executable';
56   -
57   -# Apache setup
58   -$mt->render_to_file(<<'EOF', $config, $dir, $port, $fcgi);
59   -% my ($dir, $port, $fcgi) = @_;
60   -% use File::Spec;
61   -ServerName 127.0.0.1
62   -Listen <%= $port %>
63   -DocumentRoot <%= $dir %>
64   -
65   -LoadModule log_config_module libexec/apache2/mod_log_config.so
66   -
67   -ErrorLog <%= File::Spec->catfile($dir, 'error.log') %>
68   -
69   -LoadModule alias_module libexec/apache2/mod_alias.so
70   -LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so
71   -
72   -PidFile <%= File::Spec->catfile($dir, 'httpd.pid') %>
73   -LockFile <%= File::Spec->catfile($dir, 'accept.lock') %>
74   -
75   -FastCgiIpcDir <%= $dir %>
76   -FastCgiServer <%= $fcgi %> -processes 1
77   -Alias / <%= $fcgi %>/
78   -EOF
79   -
80   -# Start
81   -my $pid = open my $server, '-|', '/usr/sbin/httpd', '-X', '-f', $config;
82   -sleep 1
83   - while !IO::Socket::INET->new(
84   - Proto => 'tcp',
85   - PeerAddr => 'localhost',
86   - PeerPort => $port
87   - );
88   -
89   -# Request
90   -my $ua = Mojo::UserAgent->new;
91   -my $tx = $ua->get("http://127.0.0.1:$port/");
92   -is $tx->res->code, 200, 'right status';
93   -is $tx->res->headers->content_length, 21, 'right "Content-Length" value';
94   -is $tx->res->body, 'Your Mojo is working!', 'right content';
95   -
96   -# HEAD request
97   -$tx = $ua->head("http://127.0.0.1:$port/");
98   -is $tx->res->code, 200, 'right status';
99   -is $tx->res->headers->content_length, 21, 'right "Content-Length" value';
100   -is $tx->res->body, '', 'no content';
101   -
102   -# Form with chunked response
103   -my $params = {};
104   -for my $i (1 .. 10) { $params->{"test$i"} = $i }
105   -my $result = '';
106   -for my $key (sort keys %$params) { $result .= $params->{$key} }
107   -my ($code, $body);
108   -$tx = $ua->post_form("http://127.0.0.1:$port/diag/chunked_params" => $params);
109   -is $tx->res->code, 200, 'right status';
110   -is $tx->res->body, $result, 'right content';
111   -
112   -# Upload
113   -($code, $body) = undef;
114   -$tx = $ua->post_form(
115   - "http://127.0.0.1:$port/diag/upload" => {file => {content => $result}});
116   -is $tx->res->code, 200, 'right status';
117   -is $tx->res->body, $result, 'right content';
118   -
119   -# Stop
120   -kill 'INT', $pid;
121   -sleep 1
122   - while IO::Socket::INET->new(
123   - Proto => 'tcp',
124   - PeerAddr => 'localhost',
125   - PeerPort => $port
126   - );
6 t/mojo/command.t
... ... @@ -1,7 +1,7 @@
1 1 #!/usr/bin/env perl
2 2 use Mojo::Base -strict;
3 3
4   -use Test::More tests => 24;
  4 +use Test::More tests => 23;
5 5
6 6 use Cwd 'cwd';
7 7 use File::Spec;
@@ -67,10 +67,6 @@ is $command->class_to_path('Foo::Bar'), 'Foo/Bar.pm', 'right path';
67 67 local $ENV{GATEWAY_INTERFACE} = 'CGI/1.1';
68 68 is $command->detect, 'cgi', 'right environment';
69 69 }
70   -{
71   - local %ENV = ();
72   - is $command->detect, 'fastcgi', 'right environment';
73   -}
74 70
75 71 # Generating files
76 72 my $cwd = cwd;
7 t/mojo/fastcgi.t
... ... @@ -1,7 +0,0 @@
1   -#!/usr/bin/env perl
2   -use Mojo::Base -strict;
3   -
4   -use Test::More tests => 1;
5   -
6   -# "I've gone back in time to when dinosaurs weren't just confined to zoos."
7   -use_ok 'Mojo::Server::FastCGI';

0 comments on commit a1a16bb

Please sign in to comment.
Something went wrong with that request. Please try again.