Browse Source

fixed output of non-cached compressed content and added test-cases

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@779 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.6
Jan Kneschke 17 years ago
parent
commit
51d6e2abf0
  1. 6
      src/mod_compress.c
  2. 4
      tests/lighttpd.conf
  3. 26
      tests/mod-compress.t

6
src/mod_compress.c

@ -514,7 +514,7 @@ static int deflate_file_to_buffer(server *srv, connection *con, plugin_data *p,
chunkqueue_reset(con->write_queue);
b = chunkqueue_get_append_buffer(con->write_queue);
buffer_copy_memory(b, p->b->ptr, p->b->used);
buffer_copy_memory(b, p->b->ptr, p->b->used + 1);
buffer_reset(con->physical.path);
@ -663,7 +663,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag));
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
return HANDLER_GO_ON;
}
} else if (0 == deflate_file_to_buffer(srv, con, p,
@ -672,7 +672,7 @@ PHYSICALPATH_FUNC(mod_compress_physical) {
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Encoding"), compression_name, strlen(compression_name));
response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type));
return HANDLER_GO_ON;
return HANDLER_FINISHED;
}
break;
}

4
tests/lighttpd.conf

@ -64,7 +64,9 @@ mimetype.assign = ( ".png" => "image/png",
".c" => "text/plain",
".conf" => "text/plain" )
compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
$HTTP["host"] == "cache.example.org" {
compress.cache-dir = "@SRCDIR@/tmp/lighttpd/cache/compress/"
}
compress.filetype = ("text/plain", "text/html")
setenv.add-environment = ( "TRAC_ENV" => "tracenv", "SETENV" => "setenv")

26
tests/mod-compress.t

@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 7;
use Test::More tests => 9;
use LightyTest;
my $tf = LightyTest->new();
@ -27,6 +27,16 @@ ok($tf->handle_http($t) == 0, 'Vary is set');
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: deflate
Host: no-cache.example.org
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } ];
ok($tf->handle_http($t) == 0, 'deflate - Content-Length and Content-Encoding is set');
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: deflate
Host: cache.example.org
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1288', '+Content-Encoding' => '' } ];
@ -35,11 +45,22 @@ ok($tf->handle_http($t) == 0, 'deflate - Content-Length and Content-Encoding is
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: gzip
Host: no-cache.example.org
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '' } ];
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1306', '+Content-Encoding' => '' } ];
ok($tf->handle_http($t) == 0, 'gzip - Content-Length and Content-Encoding is set');
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Accept-Encoding: gzip
Host: cache.example.org
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Length' => '1306', '+Content-Encoding' => '' } ];
ok($tf->handle_http($t) == 0, 'gzip - Content-Length and Content-Encoding is set');
$t->{REQUEST} = ( <<EOF
GET /index.txt HTTP/1.0
Accept-Encoding: gzip, deflate
@ -56,5 +77,4 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', '+Content-Encoding' => '', 'Content-Type' => "text/plain" } ];
ok($tf->handle_http($t) == 0, 'Content-Type is from the original file');
ok($tf->stop_proc == 0, "Stopping lighttpd");

Loading…
Cancel
Save