Browse Source

[core] support weak etags with If-None-Match

support weak etags with If-None-Match

(but require strong etags for Range requests)
personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
b0ae5fcbcd
  1. 10
      src/http-header-glue.c
  2. 2
      src/mod_webdav.c
  3. 6
      tests/cachable.t

10
src/http-header-glue.c

@ -158,10 +158,12 @@ int http_response_handle_cachable(server *srv, connection *con, buffer *mtime) {
*/
if ((vb = http_header_request_get(con, HTTP_HEADER_IF_NONE_MATCH, CONST_STR_LEN("If-None-Match")))) {
/* use strong etag checking for now: weak comparison must not be used
* for ranged requests
*/
if (etag_is_equal(con->physical.etag, vb->ptr, 0)) {
/*(weak etag comparison must not be used for ranged requests)*/
int range_request =
(con->conf.range_requests
&& (200 == con->http_status || 0 == con->http_status)
&& NULL != http_header_request_get(con, HTTP_HEADER_RANGE, CONST_STR_LEN("Range")));
if (etag_is_equal(con->physical.etag, vb->ptr, !range_request)) {
if (head_or_get) {
con->http_status = 304;
return HANDLER_FINISHED;

2
src/mod_webdav.c

@ -2127,7 +2127,7 @@ webdav_if_match_or_unmodified_since (connection * const con, struct stat *st)
if (NULL == st
? !buffer_is_equal_string(inm,CONST_STR_LEN("*"))
|| (errno != ENOENT && errno != ENOTDIR)
: etag_is_equal(etagb, inm->ptr, 0))
: etag_is_equal(etagb, inm->ptr, 1))
return 412; /* Precondition Failed */
}

6
tests/cachable.t

@ -152,8 +152,7 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'A quoted star is just a regular ETag');
TODO: {
local $TODO = "weak etags not allowed yet";
{
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
If-None-Match: W/$etag
@ -188,8 +187,7 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
ok($tf->handle_http($t) == 0, 'Client sent a list of ETags, the second matches');
TODO: {
local $TODO = "weak etags not allowed yet";
{
$t->{REQUEST} = ( <<EOF
GET / HTTP/1.0
If-None-Match: "12345", W/$etag

Loading…
Cancel
Save