Browse Source

Quote ETag, fixes #117

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@376 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.3.14
Jan Kneschke 17 years ago
parent
commit
5986add693
  1. 8
      src/etag.c
  2. 30
      tests/core-response.t

8
src/etag.c

@ -9,11 +9,13 @@ int etag_is_equal(buffer *etag, const char *matches) {
}
int etag_create(buffer *etag, struct stat *st) {
buffer_copy_off_t(etag, st->st_ino);
buffer_append_string_len(etag, "-", 1);
buffer_copy_string_len(etag, CONST_STR_LEN("\""));
buffer_append_off_t(etag, st->st_ino);
buffer_append_string_len(etag, CONST_STR_LEN("-"));
buffer_append_off_t(etag, st->st_size);
buffer_append_string_len(etag, "-", 1);
buffer_append_string_len(etag, CONST_STR_LEN("-"));
buffer_append_long(etag, st->st_mtime);
buffer_append_string_len(etag, CONST_STR_LEN("\""));
return 0;
}

30
tests/core-response.t

@ -2,7 +2,7 @@
use strict;
use IO::Socket;
use Test::More tests => 10;
use Test::More tests => 12;
my $basedir = (defined $ENV{'top_builddir'} ? $ENV{'top_builddir'} : '..');
my $srcdir = (defined $ENV{'srcdir'} ? $ENV{'srcdir'} : '.');
@ -172,10 +172,16 @@ sub handle_http {
return -1;
}
if ($no_val == 0 &&
$href->{$_} ne $resp_hdr{$k}) {
diag(sprintf("response-header failed: expected '%s', got '%s'\n", $href->{$_}, $resp_hdr{$k}));
return -1;
if ($no_val == 0) {
if ($href->{$_} =~ /^\/(.+)\/$/ && $resp_hdr{$k} !~ /$1/) {
diag(sprintf("response-header failed: expected '%s', got '%s', regex: %s\n",
$href->{$_}, $resp_hdr{$k}, $1));
return -1;
} elsif ($href->{$_} ne $resp_hdr{$k}) {
diag(sprintf("response-header failed: expected '%s', got '%s'\n",
$href->{$_}, $resp_hdr{$k}));
return -1;
}
}
}
}
@ -206,6 +212,20 @@ EOF
@response = ( { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } );
ok(handle_http == 0, 'Host missing');
@request = ( <<EOF
GET / HTTP/1.0
EOF
);
@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } );
ok(handle_http == 0, 'ETag is set');
@request = ( <<EOF
GET / HTTP/1.0
EOF
);
@response = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } );
ok(handle_http == 0, 'ETag has quotes');
## Low-Level Response-Header Parsing - Content-Length

Loading…
Cancel
Save