Fix common etag match code, use it everywhere.

This commit is contained in:
Andrew McMillan 2016-06-23 00:48:07 +01:00
parent 0966e5ce68
commit 5edf66321d
3 changed files with 4 additions and 29 deletions

View File

@ -1059,7 +1059,8 @@ EOSQL;
else
$trim_chars = ' ';
if ( isset($this->etag_if_match) && $this->etag_if_match != '' && trim( $this->etag_if_match, $trim_chars) != trim( $dest_etag, $trim_chars ) ) {
if ( isset($this->etag_if_match) && $this->etag_if_match != '' && $this->etag_if_match != '*'
&& trim( $this->etag_if_match, $trim_chars) != trim( $dest_etag, $trim_chars ) ) {
/**
* RFC2068, 14.25:
* If none of the entity tags match, or if "*" is given and no current

View File

@ -79,9 +79,7 @@ if ( $dav_resource->IsCollection() ) {
$cache->releaseLock($myLock);
}
else {
if ( isset($request->etag_if_match) && $request->etag_if_match != $dav_resource->unique_tag() && $request->etag_if_match != "*" ) {
$request->DoResponse( 412, translate("Resource has changed on server - not deleted") );
}
$request->CheckEtagMatch( $dav_resource->Exists(), $dav_resource->unique_tag() );
// Check to see if we need to do any scheduling transactions for this one.
do_scheduling_for_delete($dav_resource);

View File

@ -57,31 +57,7 @@ if ( $src->IsCollection() ) {
};
}
else {
if ( (isset($request->etag_if_match) && $request->etag_if_match != '' )
|| ( isset($request->etag_none_match) && $request->etag_none_match != '') ) {
/**
* RFC2068, 14.25:
* If none of the entity tags match, or if "*" is given and no current
* entity exists, the server MUST NOT perform the requested method, and
* MUST return a 412 (Precondition Failed) response.
*
* RFC2068, 14.26:
* If any of the entity tags match the entity tag of the entity that
* would have been returned in the response to a similar GET request
* (without the If-None-Match header) on that resource, or if "*" is
* given and any current entity exists for that resource, then the
* server MUST NOT perform the requested method.
*/
$error = '';
if ( isset($request->etag_if_match) && $request->etag_if_match != $src->unique_tag() ) {
$error = translate( 'Existing resource does not match "If-Match" header - not accepted.');
}
else if ( isset($request->etag_none_match) && $request->etag_none_match != '' && $request->etag_none_match == $src->unique_tag() ) {
$error = translate( 'Existing resource matches "If-None-Match" header - not accepted.');
}
if ( $error != '' ) $request->DoResponse( 412, $error );
}
$request->CheckEtagMatch( $src->Exists(), $src->unique_tag() );
}
$src->NeedPrivilege('DAV::unbind');