diff --git a/src/etag.c b/src/etag.c index eb1b2f41..a1748783 100644 --- a/src/etag.c +++ b/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; } diff --git a/tests/core-response.t b/tests/core-response.t index 6bbb63c6..844a4295 100755 --- a/tests/core-response.t +++ b/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 = ( < 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } ); +ok(handle_http == 0, 'ETag is set'); + +@request = ( < 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } ); +ok(handle_http == 0, 'ETag has quotes'); + ## Low-Level Response-Header Parsing - Content-Length