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 => 12;
12use LightyTest;
13
14my $tf = LightyTest->new();
15my $t;
16
17ok($tf->start_proc == 0, "Starting lighttpd") or die();
18
19## Low-Level Response-Header Parsing - HTTP/1.1
20
21$t->{REQUEST}  = ( <<EOF
22GET / HTTP/1.1
23Host: www.example.org
24Connection: close
25EOF
26 );
27$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ];
28ok($tf->handle_http($t) == 0, 'Date header');
29
30$t->{REQUEST}  = ( <<EOF
31GET / HTTP/1.1
32EOF
33 );
34$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ];
35ok($tf->handle_http($t) == 0, 'Host missing');
36
37$t->{REQUEST}  = ( <<EOF
38GET / HTTP/1.0
39EOF
40 );
41$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } ];
42ok($tf->handle_http($t) == 0, 'ETag is set');
43
44$t->{REQUEST}  = ( <<EOF
45GET / HTTP/1.0
46EOF
47 );
48$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } ];
49ok($tf->handle_http($t) == 0, 'ETag has quotes');
50
51
52
53## Low-Level Response-Header Parsing - Content-Length
54
55
56$t->{REQUEST}  = ( <<EOF
57GET /12345.html HTTP/1.0
58Host: 123.example.org
59EOF
60 );
61$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
62ok($tf->handle_http($t) == 0, 'Content-Length for text/html');
63
64$t->{REQUEST}  = ( <<EOF
65GET /12345.txt HTTP/1.0
66Host: 123.example.org
67EOF
68 );
69$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
70ok($tf->handle_http($t) == 0, 'Content-Length for text/plain');
71
72
73## Low-Level Response-Header Parsing - Location
74
75$t->{REQUEST}  = ( <<EOF
76GET /dummydir HTTP/1.0
77EOF
78 );
79$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/' } ];
80ok($tf->handle_http($t) == 0, 'internal redirect in directory');
81
82$t->{REQUEST}  = ( <<EOF
83GET /dummydir?foo HTTP/1.0
84EOF
85 );
86$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/dummydir/?foo' } ];
87ok($tf->handle_http($t) == 0, 'internal redirect in directory + querystring');
88
89## simple-vhost
90
91$t->{REQUEST}  = ( <<EOF
92GET /12345.txt HTTP/1.0
93Host: no-simple.example.org
94EOF
95 );
96$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
97ok($tf->handle_http($t) == 0, 'disabling simple-vhost via conditionals');
98
99$t->{REQUEST}  = ( <<EOF
100GET /12345.txt HTTP/1.0
101Host: simple.example.org
102EOF
103 );
104$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
105ok($tf->handle_http($t) == 0, 'simple-vhost via conditionals');
106
107ok($tf->stop_proc == 0, "Stopping lighttpd");
108
109