fixed behavior of GET or HEAD with If-None-Match returning "304 Not Modified" instead of "412 Precondition Failed", if no If-Match header given

This commit is contained in:
Ralf Becker 2011-10-08 18:27:02 +00:00
parent 4613f6eb8a
commit 5b3d0c3ca2

View File

@ -285,20 +285,24 @@ abstract class groupdav_handler
if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_MATCH='$_SERVER[HTTP_IF_MATCH]', etag='$etag': 412 Precondition failed");
return '412 Precondition Failed';
}
else
{
// if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date
if ($method == 'GET' && isset($_SERVER['HTTP_IF_NONE_MATCH']))
{
if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified");
return '304 Not Modified';
}
}
}
if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
{
if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed");
return '412 Precondition Failed';
$if_none_match = $_SERVER['HTTP_IF_NONE_MATCH'];
// strip of quotes around etag, if they exist, that way we allow etag with and without quotes
if ($if_none_match[0] == '"') $if_none_match = substr($if_none_match, 1, -1);
// if an IF_NONE_MATCH is given, check if we need to send a new export, or the current one is still up-to-date
if (in_array($method, array('GET','HEAD')) && $etag === $if_none_match)
{
if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 304 Not Modified");
return '304 Not Modified';
}
if ($method == 'PUT' && ($if_none_match == '*' || $if_none_match == $etag))
{
if ($this->debug) error_log(__METHOD__."($method,,$id) HTTP_IF_NONE_MATCH='$_SERVER[HTTP_IF_NONE_MATCH]', etag='$etag': 412 Precondition failed");
return '412 Precondition Failed';
}
}
}
return $entry;