1#!/usr/bin/env perl 2BEGIN { 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; 7} 8 9use strict; 10use IO::Socket; 11use Test::More tests => 7; 12use LightyTest; 13 14my $tf = LightyTest->new(); 15my $t; 16 17ok($tf->start_proc == 0, "Starting lighttpd") or die(); 18 19$t->{REQUEST} = ( <<EOF 20GET /redirect/ HTTP/1.0 21Host: vvv.example.org 22EOF 23 ); 24$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/' } ]; 25ok($tf->handle_http($t) == 0, 'external redirect'); 26 27$t->{REQUEST} = ( <<EOF 28GET /redirect/ HTTP/1.0 29Host: vvv.example.org 30EOF 31 ); 32$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/', 'Content-Length' => '0' } ]; 33ok($tf->handle_http($t) == 0, 'external redirect should have a Content-Length: 0'); 34 35$t->{REQUEST} = ( <<EOF 36GET /redirect/ HTTP/1.0 37Host: zzz.example.org 38EOF 39 ); 40$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/zzz' } ]; 41ok($tf->handle_http($t) == 0, 'external redirect with cond regsub'); 42 43$t->{REQUEST} = ( <<EOF 44GET /redirect/ HTTP/1.0 45Host: remoteip.example.org 46EOF 47 ); 48$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/127.0.0.1' } ]; 49ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip'); 50 51$t->{REQUEST} = ( <<EOF 52GET /redirect/ HTTP/1.0 53Host: remoteip2.example.org 54EOF 55 ); 56$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/remoteip2' } ]; 57ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip2'); 58 59ok($tf->stop_proc == 0, "Stopping lighttpd"); 60