Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 94 lines (76 sloc) 2.52 kb
9d2383d mala add Impl::FCGI::EV
mala authored
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/;
9797d9c Yuval Kogman use parent instead of use base
nothingmuch authored
10 use parent qw/Exporter/;
9d2383d mala add Impl::FCGI::EV
mala authored
11
12 # this file is copied from Catalyst. thanks!
13
a32cb7a Tatsuhiko Miyagawa make FCGIDispatcher a separate CPAN distro
miyagawa authored
14 our @EXPORT = qw/ test_lighty_external /;
cd1b0a7 Tatsuhiko Miyagawa Added Plack::Middleware::FCGIDispatcher and tests
miyagawa authored
15
9d2383d mala add Impl::FCGI::EV
mala authored
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
ecdf5e6 Yury Zavarin Workaround for lighttpd changing the version string format.
tadam authored
29 my $ver = (`$lighttpd_bin -v` =~ m!lighttpd[-/]1.(\d+\.\d+)!)[0];
58361b9 Tatsuhiko Miyagawa lighttpd < 1.4.17 has bugs that adds extra Content-Length: 0 in 304 resp...
miyagawa authored
30 if ($ver < 4.17) {
31 plan skip_all => "Too old lighttpd (1.$ver), known to be broken";
32 }
33
4bdfb57 Tatsuhiko Miyagawa diag lighttpd output
miyagawa authored
34 diag "Testing with lighttpd 1.$ver";
c2c8a23 Tatsuhiko Miyagawa Kill the lighttpd workaround and added more detailed documentations how ...
miyagawa authored
35
9d2383d mala add Impl::FCGI::EV
mala authored
36 my $tmpdir = File::Temp::tempdir( CLEANUP => 1 );
37
38 test_tcp(
39 client => sub {
4bdfb57 Tatsuhiko Miyagawa diag lighttpd output
miyagawa authored
40 $callback->($lighty_port, $fcgi_port, ($ver && $ver < 4.23));
9d2383d mala add Impl::FCGI::EV
mala authored
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) = @_;
ba994f4 Tatsuhiko Miyagawa Added a test for SCRIPT_NAME in lighttpd FCGI handler. This is a unit te...
miyagawa authored
70 my $script_name = $ENV{PLACK_TEST_SCRIPT_NAME} || '/';
9d2383d mala add Impl::FCGI::EV
mala authored
71 <<"END";
72 # basic lighttpd config file for testing fcgi(external server)+Plack
0f1a9df Tatsuhiko Miyagawa Fixed a FCGI.pm bug where HTTP headers are sent with LF not CRLF.
miyagawa authored
73 server.modules += ("mod_fastcgi")
9d2383d mala add Impl::FCGI::EV
mala authored
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 = (
ba994f4 Tatsuhiko Miyagawa Added a test for SCRIPT_NAME in lighttpd FCGI handler. This is a unit te...
miyagawa authored
82 "$script_name" => ((
9d2383d mala add Impl::FCGI::EV
mala authored
83 "check-local" => "disable",
84 "host" => "127.0.0.1",
85 "port" => $fcgiport,
86 "idle-timeout" => 20,
c2c8a23 Tatsuhiko Miyagawa Kill the lighttpd workaround and added more detailed documentations how ...
miyagawa authored
87 "fix-root-scriptname" => "enable", # for 1.4.23 or later
0f1a9df Tatsuhiko Miyagawa Fixed a FCGI.pm bug where HTTP headers are sent with LF not CRLF.
miyagawa authored
88 ))
9d2383d mala add Impl::FCGI::EV
mala authored
89 )
90 END
91 }
92
93 1;
Something went wrong with that request. Please try again.