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

support weak etags with If-None-Match

(but require strong etags for Range requests)
This commit is contained in:
Glenn Strauss 2019-05-05 23:02:24 -04:00
parent 1a325a196c
commit b0ae5fcbcd
3 changed files with 9 additions and 9 deletions

View File

@ -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;

View File

@ -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 */
}

View File

@ -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