3
# add current source dir to the include-path
4
# we need this for make distcheck
5
(my $srcdir = $0) =~ s#/[^/]+$#/#;
11
use Test::More tests => 29;
14
my $tf = LightyTest->new();
17
ok($tf->start_proc == 0, "Starting lighttpd") or die();
19
## Basic Request-Handling
21
$t->{REQUEST} = ( <<EOF
25
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
26
ok($tf->handle_http($t) == 0, 'file not found');
28
$t->{REQUEST} = ( <<EOF
29
GET /foobar?foobar HTTP/1.0
32
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
33
ok($tf->handle_http($t) == 0, 'file not found + querystring');
35
$t->{REQUEST} = ( <<EOF
36
GET /12345.txt HTTP/1.0
40
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain' } ];
41
ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype text/plain');
43
$t->{REQUEST} = ( <<EOF
44
GET /12345.html HTTP/1.0
48
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/html' } ];
49
ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype text/html');
51
$t->{REQUEST} = ( <<EOF
52
GET /dummyfile.bla HTTP/1.0
56
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'application/octet-stream' } ];
57
ok($tf->handle_http($t) == 0, 'GET, content == 12345, mimetype application/octet-stream');
59
$t->{REQUEST} = ( <<EOF
63
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } ];
64
ok($tf->handle_http($t) == 0, 'POST request, no Content-Length');
67
$t->{REQUEST} = ( <<EOF
69
Content-type: application/x-www-form-urlencoded
73
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
74
ok($tf->handle_http($t) == 0, 'POST request, empty request-body');
76
$t->{REQUEST} = ( <<EOF
80
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => ''} ];
81
ok($tf->handle_http($t) == 0, 'HEAD request, no content');
83
$t->{REQUEST} = ( <<EOF
84
HEAD /12345.html HTTP/1.0
88
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} ];
89
ok($tf->handle_http($t) == 0, 'HEAD request, mimetype text/html, content-length');
91
$t->{REQUEST} = ( <<EOF
92
HEAD /foobar?foobar HTTP/1.0
95
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, '-HTTP-Content' => '' } ];
96
ok($tf->handle_http($t) == 0, 'HEAD request, file-not-found, query-string');
98
$t->{REQUEST} = ( <<EOF
104
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} ];
105
ok($tf->handle_http($t) == 0, 'Continue, Expect');
109
$t->{REQUEST} = ( <<EOF
110
GET /12345.txt HTTP/1.0
111
Host: 123.example.org
115
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } ];
116
ok($tf->handle_http($t) == 0, 'GET, Range 0-3');
118
$t->{REQUEST} = ( <<EOF
119
GET /12345.txt HTTP/1.0
120
Host: 123.example.org
124
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
125
ok($tf->handle_http($t) == 0, 'GET, Range -3');
127
$t->{REQUEST} = ( <<EOF
128
GET /12345.txt HTTP/1.0
129
Host: 123.example.org
133
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
134
ok($tf->handle_http($t) == 0, 'GET, Range 3-');
136
$t->{REQUEST} = ( <<EOF
137
GET /12345.txt HTTP/1.0
138
Host: 123.example.org
142
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
145
Content-Range: bytes 0-1/6\r
146
Content-Type: text/plain\r
150
Content-Range: bytes 3-4/6\r
151
Content-Type: text/plain\r
157
ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4');
159
$t->{REQUEST} = ( <<EOF
160
GET /12345.txt HTTP/1.0
161
Host: 123.example.org
165
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
166
ok($tf->handle_http($t) == 0, 'GET, Range 0--');
168
$t->{REQUEST} = ( <<EOF
169
GET /12345.txt HTTP/1.0
170
Host: 123.example.org
174
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
175
ok($tf->handle_http($t) == 0, 'GET, Range -2-3');
177
$t->{REQUEST} = ( <<EOF
178
GET /12345.txt HTTP/1.0
179
Host: 123.example.org
183
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
184
<?xml version="1.0" encoding="iso-8859-1"?>
185
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
186
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
187
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
189
<title>416 - Requested Range Not Satisfiable</title>
192
<h1>416 - Requested Range Not Satisfiable</h1>
197
ok($tf->handle_http($t) == 0, 'GET, Range -0');
199
$t->{REQUEST} = ( <<EOF
200
GET /12345.txt HTTP/1.0
201
Host: 123.example.org
205
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
206
<?xml version="1.0" encoding="iso-8859-1"?>
207
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
208
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
209
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
211
<title>416 - Requested Range Not Satisfiable</title>
214
<h1>416 - Requested Range Not Satisfiable</h1>
220
ok($tf->handle_http($t) == 0, 'GET, Range start out of range');
223
$t->{REQUEST} = ( <<EOF
231
jfusfdngmd: gfjgfdusdfg
236
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
237
ok($tf->handle_http($t) == 0, 'larger headers');
240
$t->{REQUEST} = ( <<EOF
242
Host: www.example.org
243
Host: 123.example.org
246
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
247
ok($tf->handle_http($t) == 0, 'Duplicate Host headers, Bug #25');
250
$t->{REQUEST} = ( <<EOF
256
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
257
ok($tf->handle_http($t) == 0, 'Duplicate Content-Length headers');
259
$t->{REQUEST} = ( <<EOF
265
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
266
ok($tf->handle_http($t) == 0, 'Duplicate Content-Type headers');
268
$t->{REQUEST} = ( <<EOF
274
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
275
ok($tf->handle_http($t) == 0, 'Duplicate Range headers');
277
$t->{REQUEST} = ( <<EOF
283
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
284
ok($tf->handle_http($t) == 0, 'Duplicate If-None-Match headers');
286
$t->{REQUEST} = ( <<EOF
292
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
293
ok($tf->handle_http($t) == 0, 'Duplicate If-Modified-Since headers');
295
$t->{REQUEST} = ( <<EOF
296
GET /range.pdf HTTP/1.0
300
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
301
ok($tf->handle_http($t) == 0, 'GET, Range with range-requests-disabled');
305
ok($tf->stop_proc == 0, "Stopping lighttpd");