Changeset 72

Show
Ignore:
Timestamp:
03/02/2005 11:27:02 AM (3 years ago)
Author:
jan
Message:

seperated the tests for each section and let run-tests.pl use Test::Harness

Location:
trunk/tests
Files:
11 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/tests/Makefile.am

    r62 r72  
    2222      fastcgi-13.conf \ 
    2323      bug-06.conf \ 
    24       bug-12.conf 
     24      bug-12.conf \ 
     25      core-request.t \ 
     26      core-response.t \ 
     27      core.t \ 
     28      mod-access.t \ 
     29      mod-auth.t \ 
     30      mod-cgi.t \ 
     31      mod-compress.t \ 
     32      mod-fastcgi.t \ 
     33      mod-redirect.t \ 
     34      mod-userdir.t \ 
     35      request.t  
     36 
    2537 
    2638TESTS_ENVIRONMENT=$(srcdir)/wrapper.sh $(srcdir) $(top_builddir) 
  • trunk/tests/run-tests.pl

    r69 r72  
    22 
    33use strict; 
    4 use IO::Socket; 
    5 use Test::More tests => 126; 
    64 
    7 my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '.'); 
     5use Test::Harness qw(&runtests $verbose);  
     6$verbose=0;  
     7 
    88my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.'); 
    99 
    10 my $testname; 
    11 my @request; 
    12 my @response; 
    13 my $configfile = $srcdir.'/lighttpd.conf'; 
    14 my $lighttpd_path = $basedir.'/src/lighttpd'; 
    15 my $pidfile = '/tmp/lighttpd/lighttpd.pid'; 
    16 my $pidoffile = '/tmp/lighttpd/pidof.pid'; 
    17  
    18 sub pidof { 
    19         my $prog = $_[0]; 
    20  
    21         open F, "ps ax  | grep $prog | awk '{ print \$1 }'|" or 
    22         open F, "ps -ef | grep $prog | awk '{ print \$2 }'|" or 
    23           return -1; 
    24  
    25         my $pid = <F>; 
    26         close F; 
    27  
    28         return $pid; 
    29 } 
    30  
    31 sub stop_proc { 
    32         open F, $pidfile or return -1; 
    33         my $pid = <F>; 
    34         close F; 
    35  
    36         kill('TERM',$pid) or return -1; 
    37         select(undef, undef, undef, 0.01); 
    38  
    39         return 0; 
    40 } 
    41  
    42  
    43 sub start_proc { 
    44         # kill old proc if necessary 
    45         stop_proc; 
    46  
    47         unlink($pidfile); 
    48         system($lighttpd_path." -f ".$configfile); 
    49  
    50         if (-e $pidfile) { 
    51                 return 0; 
    52         } else { 
    53                 return -1; 
     10opendir DIR, $srcdir; 
     11my (@fs, $f); 
     12while ($f = readdir(DIR)) { 
     13        if ($f =~ /\.t$/) { 
     14                push @fs, $srcdir.'/'.$f; 
    5415        } 
    5516} 
     17closedir DIR; 
     18runtests @fs; 
    5619 
    57 sub handle_http { 
    58         my $EOL = "\015\012"; 
    59         my $BLANK = $EOL x 2; 
    60         my $port = 2048; 
    61         my $host = "127.0.0.1"; 
    62  
    63         my $remote =  
    64           IO::Socket::INET->new(Proto    => "tcp", 
    65                                 PeerAddr => $host, 
    66                                 PeerPort => $port) 
    67           or return -1; 
    68  
    69         $remote->autoflush(1); 
    70  
    71         foreach(@request) { 
    72                 # pipeline requests 
    73                 s/\r//g; 
    74                 s/\n/$EOL/g; 
    75  
    76                 print $remote $_.$BLANK;         
    77         } 
    78  
    79         my $lines = ""; 
    80  
    81         # read everything 
    82         while(<$remote>) { 
    83                 $lines .= $_; 
    84         } 
    85          
    86         close $remote; 
    87  
    88         my $href; 
    89         foreach $href (@response) { 
    90                 # first line is always response header 
    91                 my %resp_hdr; 
    92                 my $resp_body; 
    93                 my $resp_line; 
    94                 my $conditions = $_; 
    95  
    96                 for (my $ln = 0; defined $lines; $ln++) { 
    97                         (my $line, $lines) = split($EOL, $lines, 2); 
    98  
    99                         # header finished 
    100                         last if(length($line) == 0); 
    101  
    102                         if ($ln == 0) { 
    103                                 # response header 
    104                                 $resp_line = $line; 
    105                         } else { 
    106                                 # response vars 
    107  
    108                                 if ($line =~ /^([^:]+):\s*(.+)$/) { 
    109                                         (my $h = $1) =~ tr/[A-Z]/[a-z]/; 
    110  
    111                                         $resp_hdr{$h} = $2; 
    112                                 } else { 
    113                                         return -1; 
    114                                 } 
    115                         } 
    116                 } 
    117  
    118                 # check length 
    119                 if (defined $resp_hdr{"content-length"}) { 
    120                         ($resp_body, $lines) = split("^.".$resp_hdr{"content-length"}, $lines, 2); 
    121                 } else { 
    122                         $resp_body = $lines; 
    123                         undef $lines; 
    124                 } 
    125  
    126                 # check conditions 
    127                 if ($resp_line =~ /^(HTTP\/1\.[01]) ([0-9]{3}) .+$/) { 
    128                         if ($href->{'HTTP-Protocol'} ne $1) { 
    129                                 diag(sprintf("proto failed: expected '%s', got '%s'\n", $href->{'HTTP-Protocol'}, $1)); 
    130                                 return -1; 
    131                         } 
    132                         if ($href->{'HTTP-Status'} ne $2) { 
    133                                 diag(sprintf("status failed: expected '%s', got '%s'\n", $href->{'HTTP-Status'}, $2)); 
    134                                 return -1; 
    135                         } 
    136                 } else { 
    137                         return -1; 
    138                 } 
    139  
    140                 if (defined $href->{'HTTP-Content'}) { 
    141                         if ($href->{'HTTP-Content'} ne $resp_body) { 
    142                                 diag(sprintf("body failed: expected '%s', got '%s'\n", $href->{'HTTP-Content'}, $resp_body)); 
    143                                 return -1; 
    144                         } 
    145                 } 
    146                  
    147                 if (defined $href->{'-HTTP-Content'}) { 
    148                         if (defined $resp_body && $resp_body ne '') { 
    149                                 diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body)); 
    150                                 return -1; 
    151                         } 
    152                 } 
    153  
    154                 foreach (keys %{ $href }) { 
    155                         next if $_ eq 'HTTP-Protocol'; 
    156                         next if $_ eq 'HTTP-Status'; 
    157                         next if $_ eq 'HTTP-Content'; 
    158                         next if $_ eq '-HTTP-Content'; 
    159  
    160                         (my $k = $_) =~ tr/[A-Z]/[a-z]/; 
    161  
    162                         my $no_val = 0; 
    163  
    164                         if (substr($k, 0, 1) eq '+') { 
    165                                 $k = substr($k, 1); 
    166                                 $no_val = 1; 
    167  
    168                         } 
    169  
    170                         if (!defined $resp_hdr{$k}) { 
    171                                 diag(sprintf("required header '%s' is missing\n", $k)); 
    172                                 return -1; 
    173                         } 
    174  
    175                         if ($no_val == 0 && 
    176                                 $href->{$_} ne $resp_hdr{$k}) { 
    177                                 diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k})); 
    178                                 return -1; 
    179                         } 
    180                 } 
    181         } 
    182  
    183         # we should have sucked up everything 
    184         return -1 if (defined $lines);  
    185  
    186         return 0; 
    187 } 
    188      
    189 print "\nStart-Up\n"; 
    190 ok(start_proc == 0, "Starting lighttpd") or die(); 
    191  
    192 print "\nRequest Line\n"; 
    193  
    194 @request  = ( <<EOF 
    195 GET / HTTP/1.0 
    196 EOF 
    197  ); 
    198 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    199 ok(handle_http == 0, 'Valid HTTP/1.0 Request') or die(); 
    200  
    201 @request  = ( <<EOF 
    202 GET / 
    203 EOF 
    204  ); 
    205 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    206 ok(handle_http == 0, 'missing Protocol'); 
    207  
    208 @request  = ( <<EOF 
    209 BC / 
    210 EOF 
    211  ); 
    212 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    213 ok(handle_http == 0, 'missing protocol + unknown method'); 
    214  
    215 @request  = ( <<EOF 
    216 ABC 
    217 EOF 
    218  ); 
    219 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    220 ok(handle_http == 0, 'missing protocol + unknown method + missing URI'); 
    221  
    222 @request  = ( <<EOF 
    223 ABC / HTTP/1.0 
    224 EOF 
    225  ); 
    226 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 501 } ); 
    227 ok(handle_http == 0, 'unknown method'); 
    228  
    229 @request  = ( <<EOF 
    230 GET / HTTP/1.3 
    231 EOF 
    232  ); 
    233 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 505 } ); 
    234 ok(handle_http == 0, 'unknown protocol'); 
    235  
    236 @request  = ( <<EOF 
    237 GET http://www.example.org/ HTTP/1.0 
    238 EOF 
    239  ); 
    240 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    241 ok(handle_http == 0, 'absolute URI'); 
    242  
    243 print "\nLow-Level Request-Header Parsing\n"; 
    244 @request  = ( <<EOF 
    245 GET / HTTP/1.0 
    246 ABC : foo 
    247 EOF 
    248  ); 
    249 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    250 ok(handle_http == 0, 'whitespace after key'); 
    251  
    252 @request  = ( <<EOF 
    253 GET / HTTP/1.0 
    254 ABC a: foo 
    255 EOF 
    256  ); 
    257 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    258 ok(handle_http == 0, 'whitespace with-in key'); 
    259  
    260 @request  = ( <<EOF 
    261 GET / HTTP/1.0 
    262 ABC:foo 
    263 EOF 
    264  ); 
    265 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    266 ok(handle_http == 0, 'no whitespace'); 
    267  
    268 @request  = ( <<EOF 
    269 GET / HTTP/1.0 
    270 ABC:foo  
    271   bc 
    272 EOF 
    273  ); 
    274 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    275 ok(handle_http == 0, 'line-folding'); 
    276  
    277 print "\nLow-Level Request-Header Parsing - URI\n"; 
    278 @request  = ( <<EOF 
    279 GET /index%2ehtml HTTP/1.0 
    280 EOF 
    281  ); 
    282 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    283 ok(handle_http == 0, 'URL-encoding'); 
    284  
    285 @request  = ( <<EOF 
    286 GET /index.html%00 HTTP/1.0 
    287 EOF 
    288  ); 
    289 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ); 
    290 ok(handle_http == 0, 'URL-encoding, %00'); 
    291  
    292  
    293  
    294 print "\nLow-Level Request-Header Parsing - Host:\n"; 
    295  
    296 @request  = ( <<EOF 
    297 GET / HTTP/1.0 
    298 Host: www.example.org 
    299 EOF 
    300  ); 
    301 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    302 ok(handle_http == 0, 'hostname'); 
    303  
    304 @request  = ( <<EOF 
    305 GET / HTTP/1.0 
    306 Host: 127.0.0.1 
    307 EOF 
    308  ); 
    309 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    310 ok(handle_http == 0, 'IPv4 address'); 
    311  
    312 @request  = ( <<EOF 
    313 GET / HTTP/1.0 
    314 Host: [::1] 
    315 EOF 
    316  ); 
    317 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    318 ok(handle_http == 0, 'IPv6 address'); 
    319  
    320 @request  = ( <<EOF 
    321 GET / HTTP/1.0 
    322 Host: www.example.org:80 
    323 EOF 
    324  ); 
    325 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    326 ok(handle_http == 0, 'hostname + port'); 
    327  
    328 @request  = ( <<EOF 
    329 GET / HTTP/1.0 
    330 Host: 127.0.0.1:80 
    331 EOF 
    332  ); 
    333 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    334 ok(handle_http == 0, 'IPv4 address + port'); 
    335  
    336 @request  = ( <<EOF 
    337 GET / HTTP/1.0 
    338 Host: [::1]:80 
    339 EOF 
    340  ); 
    341 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    342 ok(handle_http == 0, 'IPv6 address + port'); 
    343  
    344 @request  = ( <<EOF 
    345 GET / HTTP/1.0 
    346 Host: ../123.org 
    347 EOF 
    348  ); 
    349 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    350 ok(handle_http == 0, 'directory traversal'); 
    351  
    352 @request  = ( <<EOF 
    353 GET / HTTP/1.0 
    354 Host: .jsdh.sfdg.sdfg. 
    355 EOF 
    356  ); 
    357 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    358 ok(handle_http == 0, 'leading and trailing dot'); 
    359  
    360 @request  = ( <<EOF 
    361 GET / HTTP/1.0 
    362 Host: jsdh.sfdg.sdfg. 
    363 EOF 
    364  ); 
    365 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    366 ok(handle_http == 0, 'trailing dot is ok'); 
    367  
    368 @request  = ( <<EOF 
    369 GET / HTTP/1.0 
    370 Host: .jsdh.sfdg.sdfg 
    371 EOF 
    372  ); 
    373 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    374 ok(handle_http == 0, 'leading dot'); 
    375  
    376  
    377 @request  = ( <<EOF 
    378 GET / HTTP/1.0 
    379 Host: jsdh..sfdg.sdfg 
    380 EOF 
    381  ); 
    382 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    383 ok(handle_http == 0, 'two dots'); 
    384  
    385 @request  = ( <<EOF 
    386 GET / HTTP/1.0 
    387 Host: jsdh.sfdg.sdfg:asd 
    388 EOF 
    389  ); 
    390 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    391 ok(handle_http == 0, 'broken port-number'); 
    392  
    393 @request  = ( <<EOF 
    394 GET / HTTP/1.0 
    395 Host: jsdh.sfdg.sdfg:-1 
    396 EOF 
    397  ); 
    398 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    399 ok(handle_http == 0, 'negative port-number'); 
    400  
    401  
    402 @request  = ( <<EOF 
    403 GET / HTTP/1.0 
    404 Host: :80 
    405 EOF 
    406  ); 
    407 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    408 ok(handle_http == 0, 'port given but host missing'); 
    409  
    410 @request  = ( <<EOF 
    411 GET / HTTP/1.0 
    412 Host: .jsdh.sfdg.:sdfg. 
    413 EOF 
    414  ); 
    415 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    416 ok(handle_http == 0, 'port and host are broken'); 
    417  
    418 @request  = ( <<EOF 
    419 GET / HTTP/1.0 
    420 Host: a.b-c.d123 
    421 EOF 
    422  ); 
    423 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    424 ok(handle_http == 0, 'allowed characters in host-name'); 
    425  
    426 @request  = ( <<EOF 
    427 GET / HTTP/1.0 
    428 Host: -a.c 
    429 EOF 
    430  ); 
    431 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    432 ok(handle_http == 0, 'leading dash'); 
    433  
    434 @request  = ( <<EOF 
    435 GET / HTTP/1.0 
    436 Host: . 
    437 EOF 
    438  ); 
    439 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    440 ok(handle_http == 0, 'dot only'); 
    441  
    442 @request  = ( <<EOF 
    443 GET / HTTP/1.0 
    444 Host: a192.168.2.10:1234 
    445 EOF 
    446  ); 
    447 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    448 ok(handle_http == 0, 'broken IPv4 address - non-digit'); 
    449  
    450 @request  = ( <<EOF 
    451 GET / HTTP/1.0 
    452 Host: 192.168.2:1234 
    453 EOF 
    454  ); 
    455 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    456 ok(handle_http == 0, 'broken IPv4 address - too short'); 
    457  
    458  
    459  
    460  
    461  
    462 print "\nLow-Level Request-Header Parsing - Content-Length:\n"; 
    463 @request  = ( <<EOF 
    464 GET /index.html HTTP/1.0 
    465 Content-Length: -2 
    466 EOF 
    467  ); 
    468 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ); 
    469 ok(handle_http == 0, 'negative Content-Length'); 
    470  
    471 @request  = ( <<EOF 
    472 POST /12345.txt HTTP/1.0 
    473 Host: 123.example.org 
    474 Content-Length: 2147483648 
    475 EOF 
    476  ); 
    477 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 413 } ); 
    478 ok(handle_http == 0, 'Content-Length > max-request-size'); 
    479  
    480 @request  = ( <<EOF 
    481 POST /12345.txt HTTP/1.0 
    482 Host: 123.example.org 
    483 Content-Length:  
    484 EOF 
    485  ); 
    486 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } ); 
    487 ok(handle_http == 0, 'Content-Length is empty'); 
    488  
    489 print "\nLow-Level Request-Header Parsing - HTTP/1.1\n"; 
    490 @request  = ( <<EOF 
    491 GET / HTTP/1.1 
    492 EOF 
    493  ); 
    494 @response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400 } ); 
    495 ok(handle_http == 0, 'Host missing'); 
    496  
    497 print "\nLow-Level Response-Header Parsing - HTTP/1.1\n"; 
    498 @request  = ( <<EOF 
    499 GET / HTTP/1.1 
    500 Host: www.example.org 
    501 Connection: close 
    502 EOF 
    503  ); 
    504 @response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ); 
    505 ok(handle_http == 0, 'Date header'); 
    506  
    507 @request  = ( <<EOF 
    508 GET / HTTP/1.1 
    509 EOF 
    510  ); 
    511 @response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ); 
    512 ok(handle_http == 0, 'Host missing'); 
    513  
    514  
    515  
    516  
    517  
    518  
    519  
    520  
    521 print "\nLow-Level Response-Header Parsing - Content-Length:\n"; 
    522 @request  = ( <<EOF 
    523 GET /12345.html HTTP/1.0 
    524 Host: 123.example.org 
    525 EOF 
    526  ); 
    527 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ); 
    528 ok(handle_http == 0, 'Content-Length for text/html'); 
    529  
    530 @request  = ( <<EOF 
    531 GET /12345.txt HTTP/1.0 
    532 Host: 123.example.org 
    533 EOF 
    534  ); 
    535 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ); 
    536 ok(handle_http == 0, 'Content-Length for text/plain'); 
    537  
    538  
    539  
    540  
    541  
    542  
    543  
    544  
    545  
    546  
    547 print "\nLow-Level Response-Header Parsing - Location:\n"; 
    548 @request  = ( <<EOF 
    549 GET /dummydir HTTP/1.0 
    550 EOF 
    551  ); 
    552 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/' } ); 
    553 ok(handle_http == 0, 'internal redirect in directory'); 
    554  
    555 @request  = ( <<EOF 
    556 GET /dummydir?foo HTTP/1.0 
    557 EOF 
    558  ); 
    559 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:2048/dummydir/?foo' } ); 
    560 ok(handle_http == 0, 'internal redirect in directory + querystring'); 
    561  
    562  
    563  
    564  
    565  
    566  
    567  
    568  
    569  
    570  
    571  
    572  
    573 print "\nBasic Request-Handling\n"; 
    574 @request  = ( <<EOF 
    575 GET /foobar HTTP/1.0 
    576 EOF 
    577  ); 
    578 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ); 
    579 ok(handle_http == 0, 'file not found'); 
    580  
    581 @request  = ( <<EOF 
    582 GET /foobar?foobar HTTP/1.0 
    583 EOF 
    584  ); 
    585 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ); 
    586 ok(handle_http == 0, 'file not found + querystring'); 
    587  
    588 @request  = ( <<EOF 
    589 GET /12345.txt HTTP/1.0 
    590 Host: 123.example.org 
    591 EOF 
    592  ); 
    593 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/plain' } ); 
    594 ok(handle_http == 0, 'GET, content == 12345, mimetype text/plain'); 
    595  
    596 @request  = ( <<EOF 
    597 GET /12345.html HTTP/1.0 
    598 Host: 123.example.org 
    599 EOF 
    600  ); 
    601 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'text/html' } ); 
    602 ok(handle_http == 0, 'GET, content == 12345, mimetype text/html'); 
    603  
    604 @request  = ( <<EOF 
    605 GET /dummyfile.bla HTTP/1.0 
    606 Host: 123.example.org 
    607 EOF 
    608  ); 
    609 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '12345'."\n", 'Content-Type' => 'application/octet-stream' } ); 
    610 ok(handle_http == 0, 'GET, content == 12345, mimetype application/octet-stream'); 
    611  
    612 @request  = ( <<EOF 
    613 POST / HTTP/1.0 
    614 EOF 
    615  ); 
    616 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 411 } ); 
    617 ok(handle_http == 0, 'POST request, no Content-Length'); 
    618  
    619  
    620 @request  = ( <<EOF 
    621 POST / HTTP/1.0 
    622 Content-type: application/x-www-form-urlencoded 
    623 Content-length: 0 
    624 EOF 
    625  ); 
    626 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    627 ok(handle_http == 0, 'POST request, empty request-body'); 
    628  
    629 @request  = ( <<EOF 
    630 HEAD / HTTP/1.0 
    631 EOF 
    632  ); 
    633 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => ''} ); 
    634 ok(handle_http == 0, 'HEAD request, no content'); 
    635  
    636 @request  = ( <<EOF 
    637 HEAD /12345.html HTTP/1.0 
    638 Host: 123.example.org 
    639 EOF 
    640  ); 
    641 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '-HTTP-Content' => '', 'Content-Type' => 'text/html', 'Content-Length' => '6'} ); 
    642 ok(handle_http == 0, 'HEAD request, mimetype text/html, content-length'); 
    643  
    644 @request  = ( <<EOF 
    645 HEAD /foobar?foobar HTTP/1.0 
    646 EOF 
    647  ); 
    648 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, '-HTTP-Content' => '' } ); 
    649 ok(handle_http == 0, 'HEAD request, file-not-found, query-string'); 
    650  
    651 @request  = ( <<EOF 
    652 GET / HTTP/1.1 
    653 Connection: close 
    654 Expect: 100-continue 
    655 EOF 
    656  ); 
    657 @response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 417, '-HTTP-Content' => ''} ); 
    658 ok(handle_http == 0, 'Continue, Expect'); 
    659  
    660 ## ranges 
    661  
    662 @request  = ( <<EOF 
    663 GET /12345.txt HTTP/1.0 
    664 Host: 123.example.org 
    665 Range: bytes=0-3 
    666 EOF 
    667  ); 
    668 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '1234' } ); 
    669 ok(handle_http == 0, 'GET, Range 0-3'); 
    670  
    671 @request  = ( <<EOF 
    672 GET /12345.txt HTTP/1.0 
    673 Host: 123.example.org 
    674 Range: bytes=-3 
    675 EOF 
    676  ); 
    677 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ); 
    678 ok(handle_http == 0, 'GET, Range -3'); 
    679  
    680 @request  = ( <<EOF 
    681 GET /12345.txt HTTP/1.0 
    682 Host: 123.example.org 
    683 Range: bytes=3- 
    684 EOF 
    685  ); 
    686 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '45'."\n" } ); 
    687 ok(handle_http == 0, 'GET, Range 3-'); 
    688  
    689 @request  = ( <<EOF 
    690 GET /12345.txt HTTP/1.0 
    691 Host: 123.example.org 
    692 Range: bytes=0-1,3-4 
    693 EOF 
    694  ); 
    695 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => <<EOF 
    696 \r 
    697 --fkj49sn38dcn3\r 
    698 Content-Range: bytes 0-1/6\r 
    699 Content-Type: text/plain\r 
    700 \r 
    701 12\r 
    702 --fkj49sn38dcn3\r 
    703 Content-Range: bytes 3-4/6\r 
    704 Content-Type: text/plain\r 
    705 \r 
    706 45\r 
    707 --fkj49sn38dcn3--\r 
    708 EOF 
    709  } ); 
    710 ok(handle_http == 0, 'GET, Range 0-1,3-4'); 
    711  
    712 @request  = ( <<EOF 
    713 GET /12345.txt HTTP/1.0 
    714 Host: 123.example.org 
    715 Range: bytes=0-- 
    716 EOF 
    717  ); 
    718 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    719 ok(handle_http == 0, 'GET, Range 0--'); 
    720  
    721 @request  = ( <<EOF 
    722 GET /12345.txt HTTP/1.0 
    723 Host: 123.example.org 
    724 Range: bytes=-2-3 
    725 EOF 
    726  ); 
    727 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ); 
    728 ok(handle_http == 0, 'GET, Range -2-3'); 
    729  
    730 @request  = ( <<EOF 
    731 GET /12345.txt HTTP/1.0 
    732 Host: 123.example.org 
    733 Range: bytes=-0 
    734 EOF 
    735  ); 
    736 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF 
    737 <?xml version="1.0" encoding="iso-8859-1"?> 
    738 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    739          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    740 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    741  <head> 
    742   <title>416 - Requested Range Not Satisfiable</title> 
    743  </head> 
    744  <body> 
    745   <h1>416 - Requested Range Not Satisfiable</h1> 
    746  </body> 
    747 </html> 
    748 EOF 
    749  } ); 
    750 ok(handle_http == 0, 'GET, Range -0'); 
    751  
    752 @request  = ( <<EOF 
    753 GET /12345.txt HTTP/1.0 
    754 Host: 123.example.org 
    755 Range: bytes=25- 
    756 EOF 
    757  ); 
    758 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 416, 'HTTP-Content' => <<EOF 
    759 <?xml version="1.0" encoding="iso-8859-1"?> 
    760 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    761          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    762 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    763  <head> 
    764   <title>416 - Requested Range Not Satisfiable</title> 
    765  </head> 
    766  <body> 
    767   <h1>416 - Requested Range Not Satisfiable</h1> 
    768  </body> 
    769 </html> 
    770 EOF 
    771  } ); 
    772  
    773 ok(handle_http == 0, 'GET, Range start out of range'); 
    774  
    775  
    776 @request  = ( <<EOF 
    777 GET / HTTP/1.0 
    778 Hsgfsdjf: asdfhdf 
    779 hdhd: shdfhfdasd 
    780 hfhr: jfghsdfg 
    781 jfuuehdmn: sfdgjfdg 
    782 jvcbzufdg: sgfdfg 
    783 hrnvcnd: jfjdfg 
    784 jfusfdngmd: gfjgfdusdfg 
    785 nfj: jgfdjdfg 
    786 jfue: jfdfdg 
    787 EOF 
    788  ); 
    789 @response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );