untangle overly complex control flow logic
[lighttpd.git] / tests / mod-redirect.t
blob14669d9711db080f900b7629c0cf5d5799b1d2a1
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 => 7;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
17 ok($tf->start_proc == 0, "Starting lighttpd") or die();
19 $t->{REQUEST} = ( <<EOF
20 GET /redirect/ HTTP/1.0
21 Host: vvv.example.org
22 EOF
24 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/' } ];
25 ok($tf->handle_http($t) == 0, 'external redirect');
27 $t->{REQUEST} = ( <<EOF
28 GET /redirect/ HTTP/1.0
29 Host: vvv.example.org
30 EOF
32 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/', 'Content-Length' => '0' } ];
33 ok($tf->handle_http($t) == 0, 'external redirect should have a Content-Length: 0');
35 $t->{REQUEST} = ( <<EOF
36 GET /redirect/ HTTP/1.0
37 Host: zzz.example.org
38 EOF
40 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/zzz' } ];
41 ok($tf->handle_http($t) == 0, 'external redirect with cond regsub');
43 $t->{REQUEST} = ( <<EOF
44 GET /redirect/ HTTP/1.0
45 Host: remoteip.example.org
46 EOF
48 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/127.0.0.1' } ];
49 ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip');
51 $t->{REQUEST} = ( <<EOF
52 GET /redirect/ HTTP/1.0
53 Host: remoteip2.example.org
54 EOF
56 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/remoteip2' } ];
57 ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip2');
59 ok($tf->stop_proc == 0, "Stopping lighttpd");