~ubuntu-branches/ubuntu/natty/lighttpd/natty

« back to all changes in this revision

Viewing changes to tests/request.t

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Marek
  • Date: 2005-11-26 11:48:51 UTC
  • Revision ID: james.westby@ubuntu.com-20051126114851-76t9q0rrwbzjnt2t
Tags: upstream-1.4.8
ImportĀ upstreamĀ versionĀ 1.4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;
 
7
}
 
8
 
 
9
use strict;
 
10
use IO::Socket;
 
11
use Test::More tests => 29;
 
12
use LightyTest;
 
13
 
 
14
my $tf = LightyTest->new();
 
15
my $t;
 
16
    
 
17
ok($tf->start_proc == 0, "Starting lighttpd") or die();
 
18
 
 
19
## Basic Request-Handling
 
20
 
 
21
$t->{REQUEST}  = ( <<EOF
 
22
GET /foobar HTTP/1.0
 
23
EOF
 
24
 );
 
25
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
 
26
ok($tf->handle_http($t) == 0, 'file not found');
 
27
 
 
28
$t->{REQUEST}  = ( <<EOF
 
29
GET /foobar?foobar HTTP/1.0
 
30
EOF
 
31
 );
 
32
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
 
33
ok($tf->handle_http($t) == 0, 'file not found + querystring');
 
34
 
 
35
$t->{REQUEST}  = ( <<EOF
 
36
GET /12345.txt HTTP/1.0
 
37
Host: 123.example.org
 
38
EOF
 
39
 );
 
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');
 
42
 
 
43
$t->{REQUEST}  = ( <<EOF
 
44
GET /12345.html HTTP/1.0
 
45
Host: 123.example.org
 
46
EOF
 
47
 );
 
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');
 
50
 
 
51
$t->{REQUEST}  = ( <<EOF
 
52
GET /dummyfile.bla HTTP/1.0
 
53
Host: 123.example.org
 
54
EOF
 
55
 );
 
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');
 
58
 
 
59
$t->{REQUEST}  = ( <<EOF
 
60
POST / HTTP/1.0
 
61
EOF
 
62
 );
 
63
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } ];
 
64
ok($tf->handle_http($t) == 0, 'POST request, no Content-Length');
 
65
 
 
66
 
 
67
$t->{REQUEST}  = ( <<EOF
 
68
POST / HTTP/1.0
 
69
Content-type: application/x-www-form-urlencoded
 
70
Content-length: 0
 
71
EOF
 
72
 );
 
73
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
74
ok($tf->handle_http($t) == 0, 'POST request, empty request-body');
 
75
 
 
76
$t->{REQUEST}  = ( <<EOF
 
77
HEAD / HTTP/1.0
 
78
EOF
 
79
 );
 
80
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => ''} ];
 
81
ok($tf->handle_http($t) == 0, 'HEAD request, no content');
 
82
 
 
83
$t->{REQUEST}  = ( <<EOF
 
84
HEAD /12345.html HTTP/1.0
 
85
Host: 123.example.org
 
86
EOF
 
87
 );
 
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');
 
90
 
 
91
$t->{REQUEST}  = ( <<EOF
 
92
HEAD /foobar?foobar HTTP/1.0
 
93
EOF
 
94
 );
 
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');
 
97
 
 
98
$t->{REQUEST}  = ( <<EOF
 
99
GET / HTTP/1.1
 
100
Connection: close
 
101
Expect: 100-continue
 
102
EOF
 
103
 );
 
104
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} ];
 
105
ok($tf->handle_http($t) == 0, 'Continue, Expect');
 
106
 
 
107
## ranges
 
108
 
 
109
$t->{REQUEST}  = ( <<EOF
 
110
GET /12345.txt HTTP/1.0
 
111
Host: 123.example.org
 
112
Range: bytes=0-3
 
113
EOF
 
114
 );
 
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');
 
117
 
 
118
$t->{REQUEST}  = ( <<EOF
 
119
GET /12345.txt HTTP/1.0
 
120
Host: 123.example.org
 
121
Range: bytes=-3
 
122
EOF
 
123
 );
 
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');
 
126
 
 
127
$t->{REQUEST}  = ( <<EOF
 
128
GET /12345.txt HTTP/1.0
 
129
Host: 123.example.org
 
130
Range: bytes=3-
 
131
EOF
 
132
 );
 
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-');
 
135
 
 
136
$t->{REQUEST}  = ( <<EOF
 
137
GET /12345.txt HTTP/1.0
 
138
Host: 123.example.org
 
139
Range: bytes=0-1,3-4
 
140
EOF
 
141
 );
 
142
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
 
143
\r
 
144
--fkj49sn38dcn3\r
 
145
Content-Range: bytes 0-1/6\r
 
146
Content-Type: text/plain\r
 
147
\r
 
148
12\r
 
149
--fkj49sn38dcn3\r
 
150
Content-Range: bytes 3-4/6\r
 
151
Content-Type: text/plain\r
 
152
\r
 
153
45\r
 
154
--fkj49sn38dcn3--\r
 
155
EOF
 
156
 } ];
 
157
ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4');
 
158
 
 
159
$t->{REQUEST}  = ( <<EOF
 
160
GET /12345.txt HTTP/1.0
 
161
Host: 123.example.org
 
162
Range: bytes=0--
 
163
EOF
 
164
 );
 
165
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
166
ok($tf->handle_http($t) == 0, 'GET, Range 0--');
 
167
 
 
168
$t->{REQUEST}  = ( <<EOF
 
169
GET /12345.txt HTTP/1.0
 
170
Host: 123.example.org
 
171
Range: bytes=-2-3
 
172
EOF
 
173
 );
 
174
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
175
ok($tf->handle_http($t) == 0, 'GET, Range -2-3');
 
176
 
 
177
$t->{REQUEST}  = ( <<EOF
 
178
GET /12345.txt HTTP/1.0
 
179
Host: 123.example.org
 
180
Range: bytes=-0
 
181
EOF
 
182
 );
 
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">
 
188
 <head>
 
189
  <title>416 - Requested Range Not Satisfiable</title>
 
190
 </head>
 
191
 <body>
 
192
  <h1>416 - Requested Range Not Satisfiable</h1>
 
193
 </body>
 
194
</html>
 
195
EOF
 
196
 } ];
 
197
ok($tf->handle_http($t) == 0, 'GET, Range -0');
 
198
 
 
199
$t->{REQUEST}  = ( <<EOF
 
200
GET /12345.txt HTTP/1.0
 
201
Host: 123.example.org
 
202
Range: bytes=25-
 
203
EOF
 
204
 );
 
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">
 
210
 <head>
 
211
  <title>416 - Requested Range Not Satisfiable</title>
 
212
 </head>
 
213
 <body>
 
214
  <h1>416 - Requested Range Not Satisfiable</h1>
 
215
 </body>
 
216
</html>
 
217
EOF
 
218
 } ];
 
219
 
 
220
ok($tf->handle_http($t) == 0, 'GET, Range start out of range');
 
221
 
 
222
 
 
223
$t->{REQUEST}  = ( <<EOF
 
224
GET / HTTP/1.0
 
225
Hsgfsdjf: asdfhdf
 
226
hdhd: shdfhfdasd
 
227
hfhr: jfghsdfg
 
228
jfuuehdmn: sfdgjfdg
 
229
jvcbzufdg: sgfdfg
 
230
hrnvcnd: jfjdfg
 
231
jfusfdngmd: gfjgfdusdfg
 
232
nfj: jgfdjdfg
 
233
jfue: jfdfdg
 
234
EOF
 
235
 );
 
236
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
237
ok($tf->handle_http($t) == 0, 'larger headers');
 
238
 
 
239
 
 
240
$t->{REQUEST}  = ( <<EOF
 
241
GET / HTTP/1.0
 
242
Host: www.example.org
 
243
Host: 123.example.org
 
244
EOF
 
245
 );
 
246
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
247
ok($tf->handle_http($t) == 0, 'Duplicate Host headers, Bug #25');
 
248
 
 
249
 
 
250
$t->{REQUEST}  = ( <<EOF
 
251
GET / HTTP/1.0
 
252
Content-Length: 5
 
253
Content-Length: 4
 
254
EOF
 
255
 );
 
256
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
257
ok($tf->handle_http($t) == 0, 'Duplicate Content-Length headers');
 
258
 
 
259
$t->{REQUEST}  = ( <<EOF
 
260
GET / HTTP/1.0
 
261
Content-Type: 5
 
262
Content-Type: 4
 
263
EOF
 
264
 );
 
265
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
266
ok($tf->handle_http($t) == 0, 'Duplicate Content-Type headers');
 
267
 
 
268
$t->{REQUEST}  = ( <<EOF
 
269
GET / HTTP/1.0
 
270
Range: bytes=5-6
 
271
Range: bytes=5-9
 
272
EOF
 
273
 );
 
274
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
275
ok($tf->handle_http($t) == 0, 'Duplicate Range headers');
 
276
 
 
277
$t->{REQUEST}  = ( <<EOF
 
278
GET / HTTP/1.0
 
279
If-None-Match: 5
 
280
If-None-Match: 4
 
281
EOF
 
282
 );
 
283
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
284
ok($tf->handle_http($t) == 0, 'Duplicate If-None-Match headers');
 
285
 
 
286
$t->{REQUEST}  = ( <<EOF
 
287
GET / HTTP/1.0
 
288
If-Modified-Since: 5
 
289
If-Modified-Since: 4
 
290
EOF
 
291
 );
 
292
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
 
293
ok($tf->handle_http($t) == 0, 'Duplicate If-Modified-Since headers');
 
294
 
 
295
$t->{REQUEST}  = ( <<EOF
 
296
GET /range.pdf HTTP/1.0
 
297
Range: bytes=0-
 
298
EOF
 
299
 );
 
300
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
 
301
ok($tf->handle_http($t) == 0, 'GET, Range with range-requests-disabled');
 
302
 
 
303
 
 
304
 
 
305
ok($tf->stop_proc == 0, "Stopping lighttpd");
 
306