Changeset 1949

Show
Ignore:
Timestamp:
08/18/2007 11:42:13 AM (13 months ago)
Author:
jan
Message:

fixed extra Content-Length header on 1xx, 204 and 304 (fixes #1102)

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r1921 r1949  
    1818  * fixed CONTENT_LENGTH = -1 in mod_cgi (#1276) 
    1919  * fixed typecast of NULL on execl() (#1235) 
     20  * fixed extra Content-Length header on 1xx, 204 and 304 (#1002) 
    2021  * fixed mysql server reconnects (#518) 
    2122 
  • trunk/src/response.c

    r1868 r1949  
    4949        if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) { 
    5050                response_header_overwrite(srv, con, CONST_STR_LEN("Transfer-Encoding"), CONST_STR_LEN("chunked")); 
     51                allow_keep_alive = 1; 
     52        } else if ((con->http_status >= 100 && con->http_status < 200) || 
     53                    con->http_status == 204 || 
     54                    con->http_status == 304) { 
     55                /* 1xx, 204 and 304 never have a content-body ->  
     56                 *   never have a Content-Length and are always  
     57                 *   able to do keep-alive 
     58                 */ 
    5159                allow_keep_alive = 1; 
    5260        } else if (con->response.content_length >= 0) { 
  • trunk/tests/LightyTest.pm

    r1593 r1949  
    254254                        (my $k = $_) =~ tr/[A-Z]/[a-z]/; 
    255255 
    256                         my $no_val = 0; 
     256                        my $verify_value = 1; 
     257                        my $key_inverted = 0; 
    257258 
    258259                        if (substr($k, 0, 1) eq '+') { 
    259260                                $k = substr($k, 1); 
    260                                 $no_val = 1; 
    261  
    262                         } 
    263  
    264                         if (!defined $resp_hdr{$k}) { 
    265                                 diag(sprintf("required header '%s' is missing\n", $k)); 
    266                                 return -1; 
    267                         } 
    268  
    269                         if ($no_val == 0) { 
     261                                $verify_value = 0; 
     262                        } elsif (substr($k, 0, 1) eq '-') { 
     263                                ## the key should NOT exist 
     264                                $k = substr($k, 1); 
     265                                $key_inverted = 1; 
     266                                $verify_value = 0; ## skip the value check 
     267                        } 
     268 
     269                        if ($key_inverted) { 
     270                                if (defined $resp_hdr{$k}) { 
     271                                        diag(sprintf("header '%s' MUST not be set\n", $k)); 
     272                                        return -1; 
     273                                } 
     274                        } else { 
     275                                if (not defined $resp_hdr{$k}) { 
     276                                        diag(sprintf("required header '%s' is missing\n", $k)); 
     277                                        return -1; 
     278                                } 
     279                        } 
     280 
     281                        if ($verify_value) { 
    270282                                if ($href->{$_} =~ /^\/(.+)\/$/) { 
    271283                                        if ($resp_hdr{$k} !~ /$1/) { 
  • trunk/tests/request.t

    r1432 r1949  
    99use strict; 
    1010use IO::Socket; 
    11 use Test::More tests => 34; 
     11use Test::More tests => 41; 
    1212use LightyTest; 
    1313 
     
    346346ok($tf->handle_http($t) == 0, 'HEAD with Content-Length'); 
    347347 
    348  
    349 $t->{REQUEST}  = ( <<EOF 
    350 GET / HTTP/1.0 
    351 If-Modified-Since: Sun, 1970 Jan 01 00:00:01 GMT 
    352 If-Modified-Since: Sun, 1970 Jan 01 00:00:01 GMT 
    353 EOF 
    354  ); 
    355 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     348$t->{REQUEST}  = ( <<EOF 
     349GET / HTTP/1.0 
     350If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     351If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     352EOF 
     353 ); 
     354$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304} ]; 
    356355ok($tf->handle_http($t) == 0, 'Duplicate If-Mod-Since, with equal timestamps'); 
    357356 
     357$t->{REQUEST}  = ( "GET / HTTP/1.0\r\nIf-Modified-Since: \0\r\n\r\n" ); 
     358$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 400 } ]; 
     359ok($tf->handle_http($t) == 0, 'invalid chars in Header values (bug #1286)'); 
     360 
     361$t->{REQUEST}  = ( "GET / HTTP/1.0\r\nIf-Modified-Since: \r\n\r\n" ); 
     362$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     363ok($tf->handle_http($t) == 0, 'empty If-Modified-Since'); 
     364 
     365$t->{REQUEST}  = ( "GET / HTTP/1.0\r\nIf-Modified-Since: foobar\r\n\r\n" ); 
     366$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     367ok($tf->handle_http($t) == 0, 'broken If-Modified-Since'); 
     368 
     369$t->{REQUEST}  = ( "GET / HTTP/1.0\r\nIf-Modified-Since: this string is too long to be a valid timestamp\r\n\r\n" ); 
     370$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ]; 
     371ok($tf->handle_http($t) == 0, 'broken If-Modified-Since'); 
     372 
     373 
     374$t->{REQUEST}  = ( <<EOF 
     375GET /index.html HTTP/1.0 
     376If-Modified-Since2: Sun, 01 Jan 2100 00:00:03 GMT 
     377If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     378EOF 
     379 ); 
     380$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ]; 
     381ok($tf->handle_http($t) == 0, 'Similar Headers (bug #1287)'); 
     382 
     383$t->{REQUEST}  = ( <<EOF 
     384GET /index.html HTTP/1.0 
     385If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     386EOF 
     387 ); 
     388$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304, 'Content-Type' => 'text/html' } ]; 
     389ok($tf->handle_http($t) == 0, 'If-Modified-Since'); 
     390 
     391$t->{REQUEST}  = ( <<EOF 
     392GET /index.html HTTP/1.0 
     393If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     394EOF 
     395 ); 
     396$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304, '-Content-Length' => '' } ]; 
     397ok($tf->handle_http($t) == 0, 'Status 304 has no Content-Length (#1002)'); 
     398 
    358399ok($tf->stop_proc == 0, "Stopping lighttpd"); 
    359400