Changeset 1946

Show
Ignore:
Timestamp:
08/18/2007 10:40:20 AM (1 year ago)
Author:
jan
Message:

don't send a Content-Length for 1xx, 204 and 304 (fixes #1002)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lighttpd-1.4.x/NEWS

    r1944 r1946  
    1919  * fixed too aggresive caching of nested conditionals (#41) 
    2020  * fixed possible overflow in unix-socket path checks on BSD (#713) 
     21  * fixed extra Content-Length header on 1xx, 204 and 304 (#1002) 
    2122  * removed config-check if passwd files exist (#1188) 
    2223   
  • branches/lighttpd-1.4.x/src/connections.c

    r1924 r1946  
    506506        case 206: /* write_queue is already prepared */ 
    507507                break; 
     508        case 204: 
    508509        case 205: /* class: header only */ 
    509510        case 304: 
     
    525526                        off_t qlen = chunkqueue_length(con->write_queue); 
    526527 
    527                         /* if we have no content for a GET/PORT request, send Content-Length: 0 
    528                          * if it is a HEAD request, don't generate a Content-Length as  
    529                          * the backend might have already cut it off */ 
    530                         if (qlen > 0 || con->request.http_method != HTTP_METHOD_HEAD) { 
     528                        /** 
     529                         * The Content-Length header only can be sent if we have content: 
     530                         * - HEAD doesn't have a content-body (but have a content-length) 
     531                         * - 1xx, 204 and 304 don't have a content-body (RFC 2616 Section 4.3) 
     532                         * 
     533                         * Otherwise generate a Content-Length header as chunked encoding is not  
     534                         * available 
     535                         */ 
     536                        if ((con->http_status >= 100 && con->http_status < 200) || 
     537                            con->http_status == 204 || 
     538                            con->http_status == 304) { 
     539                                /* no Content-Body, no Content-Length */ 
     540                        } else if (qlen > 0) { 
    531541                                buffer_copy_off_t(srv->tmp_buf, chunkqueue_length(con->write_queue)); 
    532542 
  • branches/lighttpd-1.4.x/tests/LightyTest.pm

    r1331 r1946  
    236236                                return -1; 
    237237                        } 
    238                 } 
    239                  
    240                 if (defined $href->{'-HTTP-Content'}) { 
     238                } elsif (defined $href->{'-HTTP-Content'}) { 
    241239                        if (defined $resp_body && $resp_body ne '') { 
    242240                                diag(sprintf("body failed: expected empty body, got '%s'\n", $resp_body)); 
     
    246244 
    247245                foreach (keys %{ $href }) { 
     246                        ## filter special keys 
    248247                        next if $_ eq 'HTTP-Protocol'; 
    249248                        next if $_ eq 'HTTP-Status'; 
     
    253252                        (my $k = $_) =~ tr/[A-Z]/[a-z]/; 
    254253 
    255                         my $no_val = 0; 
     254                        my $verify_value = 1; 
     255                        my $key_inverted = 0; 
    256256 
    257257                        if (substr($k, 0, 1) eq '+') { 
     258                                ## the key has to exist, but the value is ignored 
    258259                                $k = substr($k, 1); 
    259                                 $no_val = 1; 
    260  
    261                         } 
    262  
    263                         if (!defined $resp_hdr{$k}) { 
    264                                 diag(sprintf("required header '%s' is missing\n", $k)); 
    265                                 return -1; 
    266                         } 
    267  
    268                         if ($no_val == 0) { 
     260                                $verify_value = 0; 
     261                        } elsif (substr($k, 0, 1) eq '-') { 
     262                                ## the key should NOT exist 
     263                                $k = substr($k, 1); 
     264                                $key_inverted = 1; 
     265                                $verify_value = 0; ## skip the value check 
     266                        } 
     267 
     268                        if ($key_inverted) { 
     269                                if (defined $resp_hdr{$k}) { 
     270                                        diag(sprintf("required header '%s' is missing\n", $k)); 
     271                                        return -1; 
     272                                } 
     273                        } else { 
     274                                if (not defined $resp_hdr{$k}) { 
     275                                        diag(sprintf("required header '%s' is missing\n", $k)); 
     276                                        return -1; 
     277                                } 
     278                        } 
     279 
     280                        if ($verify_value) { 
    269281                                if ($href->{$_} =~ /^\/(.+)\/$/) { 
    270282                                        if ($resp_hdr{$k} !~ /$1/) { 
  • branches/lighttpd-1.4.x/tests/request.t

    r1929 r1946  
    99use strict; 
    1010use IO::Socket; 
    11 use Test::More tests => 40
     11use Test::More tests => 41
    1212use LightyTest; 
    1313 
     
    382382ok($tf->handle_http($t) == 0, 'If-Modified-Since'); 
    383383 
     384$t->{REQUEST}  = ( <<EOF 
     385GET /index.html HTTP/1.0 
     386If-Modified-Since: Sun, 01 Jan 2100 00:00:02 GMT 
     387EOF 
     388 ); 
     389$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304, '-Content-Length' => '' } ]; 
     390ok($tf->handle_http($t) == 0, 'Status 304 has no Content-Length (#1002)'); 
     391 
    384392ok($tf->stop_proc == 0, "Stopping lighttpd"); 
    385393