Annotation of embedaddon/lighttpd/tests/request.t, revision 1.1.1.1
1.1 misho 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 => 52;
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 http://123.example.org/12345.html HTTP/1.1
93: Connection: close
94: EOF
95: );
96: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} ];
97: ok($tf->handle_http($t) == 0, 'Hostname in first line, HTTP/1.1');
98:
99: $t->{REQUEST} = ( <<EOF
100: HEAD https://123.example.org/12345.html HTTP/1.0
101: EOF
102: );
103: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} ];
104: ok($tf->handle_http($t) == 0, 'Hostname in first line as https url');
105:
106: $t->{REQUEST} = ( <<EOF
107: HEAD /foobar?foobar HTTP/1.0
108: EOF
109: );
110: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, '-HTTP-Content' => '' } ];
111: ok($tf->handle_http($t) == 0, 'HEAD request, file-not-found, query-string');
112:
113: $t->{REQUEST} = ( <<EOF
114: GET / HTTP/1.1
115: Connection: close
116: Expect: 100-continue
117: EOF
118: );
119: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417 } ];
120: ok($tf->handle_http($t) == 0, 'Continue, Expect');
121:
122: ## ranges
123:
124: $t->{REQUEST} = ( <<EOF
125: GET /12345.txt HTTP/1.0
126: Host: 123.example.org
127: Range: bytes=0-3
128: EOF
129: );
130: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } ];
131: ok($tf->handle_http($t) == 0, 'GET, Range 0-3');
132:
133: $t->{REQUEST} = ( <<EOF
134: GET /12345.txt HTTP/1.0
135: Host: 123.example.org
136: Range: bytes=-3
137: EOF
138: );
139: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
140: ok($tf->handle_http($t) == 0, 'GET, Range -3');
141:
142: $t->{REQUEST} = ( <<EOF
143: GET /12345.txt HTTP/1.0
144: Host: 123.example.org
145: Range: bytes=3-
146: EOF
147: );
148: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ];
149: ok($tf->handle_http($t) == 0, 'GET, Range 3-');
150:
151: $t->{REQUEST} = ( <<EOF
152: GET /12345.txt HTTP/1.0
153: Host: 123.example.org
154: Range: bytes=0-1,3-4
155: EOF
156: );
157: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF
158: \r
159: --fkj49sn38dcn3\r
160: Content-Range: bytes 0-1/6\r
161: Content-Type: text/plain\r
162: \r
163: 12\r
164: --fkj49sn38dcn3\r
165: Content-Range: bytes 3-4/6\r
166: Content-Type: text/plain\r
167: \r
168: 45\r
169: --fkj49sn38dcn3--\r
170: EOF
171: } ];
172: ok($tf->handle_http($t) == 0, 'GET, Range 0-1,3-4');
173:
174: $t->{REQUEST} = ( <<EOF
175: GET /12345.txt HTTP/1.0
176: Host: 123.example.org
177: Range: bytes=0--
178: EOF
179: );
180: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
181: ok($tf->handle_http($t) == 0, 'GET, Range 0--');
182:
183: $t->{REQUEST} = ( <<EOF
184: GET /12345.txt HTTP/1.0
185: Host: 123.example.org
186: Range: bytes=-2-3
187: EOF
188: );
189: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
190: ok($tf->handle_http($t) == 0, 'GET, Range -2-3');
191:
192: $t->{REQUEST} = ( <<EOF
193: GET /12345.txt HTTP/1.0
194: Host: 123.example.org
195: Range: bytes=-0
196: EOF
197: );
198: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
199: <?xml version="1.0" encoding="iso-8859-1"?>
200: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
201: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
202: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
203: <head>
204: <title>416 - Requested Range Not Satisfiable</title>
205: </head>
206: <body>
207: <h1>416 - Requested Range Not Satisfiable</h1>
208: </body>
209: </html>
210: EOF
211: } ];
212: ok($tf->handle_http($t) == 0, 'GET, Range -0');
213:
214: $t->{REQUEST} = ( <<EOF
215: GET /12345.txt HTTP/1.0
216: Host: 123.example.org
217: Range: bytes=25-
218: EOF
219: );
220: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF
221: <?xml version="1.0" encoding="iso-8859-1"?>
222: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
223: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
224: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
225: <head>
226: <title>416 - Requested Range Not Satisfiable</title>
227: </head>
228: <body>
229: <h1>416 - Requested Range Not Satisfiable</h1>
230: </body>
231: </html>
232: EOF
233: } ];
234:
235: ok($tf->handle_http($t) == 0, 'GET, Range start out of range');
236:
237:
238: $t->{REQUEST} = ( <<EOF
239: GET / HTTP/1.0
240: Hsgfsdjf: asdfhdf
241: hdhd: shdfhfdasd
242: hfhr: jfghsdfg
243: jfuuehdmn: sfdgjfdg
244: jvcbzufdg: sgfdfg
245: hrnvcnd: jfjdfg
246: jfusfdngmd: gfjgfdusdfg
247: nfj: jgfdjdfg
248: jfue: jfdfdg
249: EOF
250: );
251: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
252: ok($tf->handle_http($t) == 0, 'larger headers');
253:
254:
255: $t->{REQUEST} = ( <<EOF
256: GET / HTTP/1.0
257: Host: www.example.org
258: Host: 123.example.org
259: EOF
260: );
261: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
262: ok($tf->handle_http($t) == 0, 'Duplicate Host headers, Bug #25');
263:
264:
265: $t->{REQUEST} = ( <<EOF
266: GET / HTTP/1.0
267: Content-Length: 5
268: Content-Length: 4
269: EOF
270: );
271: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
272: ok($tf->handle_http($t) == 0, 'Duplicate Content-Length headers');
273:
274: $t->{REQUEST} = ( <<EOF
275: GET / HTTP/1.0
276: Content-Type: 5
277: Content-Type: 4
278: EOF
279: );
280: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
281: ok($tf->handle_http($t) == 0, 'Duplicate Content-Type headers');
282:
283: $t->{REQUEST} = ( <<EOF
284: GET / HTTP/1.0
285: Range: bytes=5-6
286: Range: bytes=5-9
287: EOF
288: );
289: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
290: ok($tf->handle_http($t) == 0, 'Duplicate Range headers');
291:
292: $t->{REQUEST} = ( <<EOF
293: GET / HTTP/1.0
294: If-None-Match: 5
295: If-None-Match: 4
296: EOF
297: );
298: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
299: ok($tf->handle_http($t) == 0, 'Duplicate If-None-Match headers');
300:
301: $t->{REQUEST} = ( <<EOF
302: GET / HTTP/1.0
303: If-Modified-Since: 5
304: If-Modified-Since: 4
305: EOF
306: );
307: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
308: ok($tf->handle_http($t) == 0, 'Duplicate If-Modified-Since headers');
309:
310: $t->{REQUEST} = ( <<EOF
311: GET /range.pdf HTTP/1.0
312: Range: bytes=0-
313: EOF
314: );
315: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
316: ok($tf->handle_http($t) == 0, 'GET, Range with range-requests-disabled');
317:
318: $t->{REQUEST} = ( <<EOF
319: GET / HTTP/1.0
320: Content-Length: 4
321:
322: 1234
323: EOF
324: );
325: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
326: ok($tf->handle_http($t) == 0, 'GET with Content-Length');
327:
328: $t->{REQUEST} = ( <<EOF
329: OPTIONS / HTTP/1.0
330: Content-Length: 4
331:
332: 1234
333: EOF
334: );
335: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
336: ok($tf->handle_http($t) == 0, 'OPTIONS with Content-Length');
337:
338: $t->{REQUEST} = ( <<EOF
339: OPTIONS rtsp://221.192.134.146:80 RTSP/1.1
340: Host: 221.192.134.146:80
341: EOF
342: );
343: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
344: ok($tf->handle_http($t) == 0, 'OPTIONS for RTSP');
345:
346: $t->{REQUEST} = ( <<EOF
347: HEAD / HTTP/1.0
348: Content-Length: 4
349:
350: 1234
351: EOF
352: );
353: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
354: ok($tf->handle_http($t) == 0, 'HEAD with Content-Length');
355:
356: $t->{REQUEST} = ( <<EOF
357: GET /index.html HTTP/1.0
358: If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT
359: If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT
360: EOF
361: );
362: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
363: ok($tf->handle_http($t) == 0, 'Duplicate If-Mod-Since, with equal timestamps');
364:
365: $t->{REQUEST} = ( "GET / HTTP/1.0\r\nIf-Modified-Since: \0\r\n\r\n" );
366: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ];
367: ok($tf->handle_http($t) == 0, 'invalid chars in Header values (bug #1286)');
368:
369: $t->{REQUEST} = ( "GET / HTTP/1.0\r\nIf-Modified-Since: \r\n\r\n" );
370: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
371: ok($tf->handle_http($t) == 0, 'empty If-Modified-Since');
372:
373: $t->{REQUEST} = ( "GET / HTTP/1.0\r\nIf-Modified-Since: foobar\r\n\r\n" );
374: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
375: ok($tf->handle_http($t) == 0, 'broken If-Modified-Since');
376:
377: $t->{REQUEST} = ( "GET / HTTP/1.0\r\nIf-Modified-Since: this string is too long to be a valid timestamp\r\n\r\n" );
378: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
379: ok($tf->handle_http($t) == 0, 'broken If-Modified-Since');
380:
381:
382: $t->{REQUEST} = ( <<EOF
383: GET /index.html HTTP/1.0
384: If-Modified-Since2: Sun, 01 Jan 2036 00:00:03 GMT
385: If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT
386: EOF
387: );
388: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
389: ok($tf->handle_http($t) == 0, 'Similar Headers (bug #1287)');
390:
391: $t->{REQUEST} = ( <<EOF
392: GET /index.html HTTP/1.0
393: If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT
394: EOF
395: );
396: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304, 'Content-Type' => 'text/html' } ];
397: ok($tf->handle_http($t) == 0, 'If-Modified-Since');
398:
399: $t->{REQUEST} = ( <<EOF
400: GET /index.html HTTP/1.0
401: If-Modified-Since: Sun, 01 Jan 2036 00:00:02 GMT
402: EOF
403: );
404: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304, '-Content-Length' => '' } ];
405: ok($tf->handle_http($t) == 0, 'Status 304 has no Content-Length (#1002)');
406:
407: $t->{REQUEST} = ( <<EOF
408: GET /12345.txt HTTP/1.0
409: Host: 123.example.org
410: EOF
411: );
412: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain' } ];
413: $t->{SLOWREQUEST} = 1;
414: ok($tf->handle_http($t) == 0, 'GET, slow \\r\\n\\r\\n (#2105)');
415:
416: print "\nPathinfo for static files\n";
417: $t->{REQUEST} = ( <<EOF
418: GET /image.jpg/index.php HTTP/1.0
419: EOF
420: );
421: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Type' => 'image/jpeg' } ];
422: ok($tf->handle_http($t) == 0, 'static file accepting pathinfo by default');
423:
424: $t->{REQUEST} = ( <<EOF
425: GET /image.jpg/index.php HTTP/1.0
426: Host: zzz.example.org
427: EOF
428: );
429: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
430: ok($tf->handle_http($t) == 0, 'static file with forbidden pathinfo');
431:
432:
433: print "\nConnection header\n";
434: $t->{REQUEST} = ( <<EOF
435: GET /12345.txt HTTP/1.1
436: Connection : close
437: Host: 123.example.org
438: EOF
439: );
440: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
441: ok($tf->handle_http($t) == 0, 'Connection-header, spaces before ":"');
442:
443: $t->{REQUEST} = ( <<EOF
444: GET /12345.txt HTTP/1.1
445: Connection: ,close
446: Host: 123.example.org
447: EOF
448: );
449: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
450: ok($tf->handle_http($t) == 0, 'Connection-header, leading comma');
451:
452: $t->{REQUEST} = ( <<EOF
453: GET /12345.txt HTTP/1.1
454: Connection: close,,TE
455: Host: 123.example.org
456: EOF
457: );
458: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
459: ok($tf->handle_http($t) == 0, 'Connection-header, no value between two commas');
460:
461: $t->{REQUEST} = ( <<EOF
462: GET /12345.txt HTTP/1.1
463: Connection: close, ,TE
464: Host: 123.example.org
465: EOF
466: );
467: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
468: ok($tf->handle_http($t) == 0, 'Connection-header, space between two commas');
469:
470: $t->{REQUEST} = ( <<EOF
471: GET /12345.txt HTTP/1.1
472: Connection: close,
473: Host: 123.example.org
474: EOF
475: );
476: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
477: ok($tf->handle_http($t) == 0, 'Connection-header, comma after value');
478:
479: $t->{REQUEST} = ( <<EOF
480: GET /12345.txt HTTP/1.1
481: Connection: close,
482: Host: 123.example.org
483: EOF
484: );
485: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain', 'Connection' => 'close' } ];
486: ok($tf->handle_http($t) == 0, 'Connection-header, comma and space after value');
487:
488: ok($tf->stop_proc == 0, "Stopping lighttpd");
489:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>