[autobuild] allow sendfile() in cross-compile (fixes #2836)
[lighttpd.git] / tests / mod-rewrite.t
blob615ac7be51bdd6506b66e1bde813ef0eb0f20e97
1 #!/usr/bin/env perl
2 BEGIN {
3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s,/[^/]+$,/,;
6 unshift @INC, $srcdir;
9 use strict;
10 use IO::Socket;
11 use Test::More tests => 8;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
16 my $php_child = -1;
18 SKIP: {
19 skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
20 skip "no php binary found", 1 unless $LightyTest::HAVE_PHP;
21 ok(-1 != ($php_child = $tf->spawnfcgi($ENV{'PHP'}, 1026)), "Spawning php");
24 SKIP: {
25 skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
27 ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
29 $t->{REQUEST} = ( <<EOF
30 GET /rewrite/foo HTTP/1.0
31 Host: www.example.org
32 EOF
34 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
35 ok($tf->handle_http($t) == 0, 'valid request');
37 $t->{REQUEST} = ( <<EOF
38 GET /rewrite/foo?a=b HTTP/1.0
39 Host: www.example.org
40 EOF
42 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } ];
43 ok($tf->handle_http($t) == 0, 'valid request');
45 $t->{REQUEST} = ( <<EOF
46 GET /rewrite/bar?a=b HTTP/1.0
47 Host: www.example.org
48 EOF
50 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } ];
51 ok($tf->handle_http($t) == 0, 'valid request');
53 $t->{REQUEST} = ( <<EOF
54 GET /rewrite/nofile?a=b HTTP/1.0
55 Host: www.example.org
56 EOF
58 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'file=/rewrite/nofile&a=b' } ];
59 ok($tf->handle_http($t) == 0, 'not existing file rewrite');
61 ok($tf->stop_proc == 0, "Stopping lighttpd");
64 SKIP: {
65 skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
66 ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
70 exit 0;
72 cleanup: ;
74 $tf->endspawnfcgi($php_child) if $php_child != -1;
76 die();