Skip to content
This repository
Newer
Older
100644 93 lines (76 sloc) 2.52 kb
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
1 package t::FCGIUtils;
2 use strict;
3 use warnings;
4 use File::Temp ();
5 use FindBin;
6 use Test::More;
7 use IO::Socket;
8 use File::Spec;
9 use Test::TCP qw/test_tcp empty_port/;
9797d9c0 » nothingmuch
2009-10-14 use parent instead of use base
10 use parent qw/Exporter/;
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
11
12 # this file is copied from Catalyst. thanks!
13
a32cb7ae » miyagawa
2011-05-31 make FCGIDispatcher a separate CPAN distro
14 our @EXPORT = qw/ test_lighty_external /;
cd1b0a7f » miyagawa
2009-10-03 Added Plack::Middleware::FCGIDispatcher and tests
15
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
16 # test for FCGI External Server
17 sub test_lighty_external (&@) {
18 my ($callback, $lighty_port, $fcgi_port) = @_;
19
20 $lighty_port ||= empty_port();
21 $fcgi_port ||= empty_port($lighty_port);
22
23 my $lighttpd_bin = $ENV{LIGHTTPD_BIN} || `which lighttpd`;
24 chomp $lighttpd_bin;
25
26 plan skip_all => 'Please set LIGHTTPD_BIN to the path to lighttpd'
27 unless $lighttpd_bin && -x $lighttpd_bin;
28
ecdf5e64 » tadam
2010-03-29 Workaround for lighttpd changing the version string format.
29 my $ver = (`$lighttpd_bin -v` =~ m!lighttpd[-/]1.(\d+\.\d+)!)[0];
58361b91 » miyagawa
2010-03-30 lighttpd < 1.4.17 has bugs that adds extra Content-Length: 0 in 304 r…
30 if ($ver < 4.17) {
31 plan skip_all => "Too old lighttpd (1.$ver), known to be broken";
32 }
33
4bdfb577 » miyagawa
2010-03-25 diag lighttpd output
34 diag "Testing with lighttpd 1.$ver";
c2c8a23d » miyagawa
2010-03-25 Kill the lighttpd workaround and added more detailed documentations h…
35
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
36 my $tmpdir = File::Temp::tempdir( CLEANUP => 1 );
37
38 test_tcp(
39 client => sub {
4bdfb577 » miyagawa
2010-03-25 diag lighttpd output
40 $callback->($lighty_port, $fcgi_port, ($ver && $ver < 4.23));
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
41 warn `cat $tmpdir/error.log` if $ENV{DEBUG};
42 },
43 server => sub {
44 my $conffname = File::Spec->catfile($tmpdir, "lighty.conf");
45 _write_file($conffname => _render_conf($tmpdir, $lighty_port, $fcgi_port));
46
47 my $pid = open my $lighttpd, "$lighttpd_bin -D -f $conffname 2>&1 |"
48 or die "Unable to spawn lighttpd: $!";
49 $SIG{TERM} = sub {
50 kill 'INT', $pid;
51 close $lighttpd;
52 exit;
53 };
54 sleep 60; # waiting tests.
55 die "server timeout";
56 },
57 port => $lighty_port,
58 );
59 }
60
61 sub _write_file {
62 my ($fname, $src) = @_;
63 open my $fh, '>', $fname or die $!;
64 print {$fh} $src or die $!;
65 close $fh;
66 }
67
68 sub _render_conf {
69 my ($tmpdir, $port, $fcgiport) = @_;
ba994f46 » miyagawa
2010-12-25 Added a test for SCRIPT_NAME in lighttpd FCGI handler. This is a unit…
70 my $script_name = $ENV{PLACK_TEST_SCRIPT_NAME} || '/';
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
71 <<"END";
72 # basic lighttpd config file for testing fcgi(external server)+Plack
0f1a9dfe » miyagawa
2010-01-06 Fixed a FCGI.pm bug where HTTP headers are sent with LF not CRLF.
73 server.modules += ("mod_fastcgi")
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
74
75 server.document-root = "$tmpdir"
76
77 server.bind = "127.0.0.1"
78 server.port = $port
79
80 # HTTP::Engine app specific fcgi setup
81 fastcgi.server = (
ba994f46 » miyagawa
2010-12-25 Added a test for SCRIPT_NAME in lighttpd FCGI handler. This is a unit…
82 "$script_name" => ((
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
83 "check-local" => "disable",
84 "host" => "127.0.0.1",
85 "port" => $fcgiport,
86 "idle-timeout" => 20,
c2c8a23d » miyagawa
2010-03-25 Kill the lighttpd workaround and added more detailed documentations h…
87 "fix-root-scriptname" => "enable", # for 1.4.23 or later
0f1a9dfe » miyagawa
2010-01-06 Fixed a FCGI.pm bug where HTTP headers are sent with LF not CRLF.
88 ))
9d2383d2 » mala
2009-09-08 add Impl::FCGI::EV
89 )
90 END
91 }
92
93 1;
Something went wrong with that request. Please try again.