/** * For the given entry object compare it's eTag (if it has eTag properties) * with current eTag request headers (if it present). * * @param mixed &$entryObject entity resource for which etag * needs to be checked. * @param ResourceType &$resourceType Resource type of the entry * object. * @param boolean &$needToSerializeResponse On return, this will contain * True if response needs to be * serialized, False otherwise. * * @return string|null The ETag for the entry object if it has eTag properties * NULL otherwise. */ protected function compareETag(&$entryObject, ResourceType &$resourceType, &$needToSerializeResponse) { $needToSerializeResponse = true; $eTag = null; $ifMatch = $this->_serviceHost->getRequestIfMatch(); $ifNoneMatch = $this->_serviceHost->getRequestIfNoneMatch(); if (is_null($entryObject)) { if (!is_null($ifMatch)) { throw ODataException::createPreConditionFailedError(Messages::eTagNotAllowedForNonExistingResource()); } return null; } if ($this->config->getValidateETagHeader() && !$resourceType->hasETagProperties()) { if (!is_null($ifMatch) || !is_null($ifNoneMatch)) { // No eTag properties but request has eTag headers, bad request throw ODataException::createBadRequestError(Messages::noETagPropertiesForType()); } // We need write the response but no eTag header return null; } if (!$this->config->getValidateETagHeader()) { // Configuration says do not validate ETag so we will not write ETag header in the // response even though the requested resource support it return null; } if (is_null($ifMatch) && is_null($ifNoneMatch)) { // No request eTag header, we need to write the response // and eTag header } else { if (strcmp($ifMatch, '*') == 0) { // If-Match:* => we need to write the response and eTag header } else { if (strcmp($ifNoneMatch, '*') == 0) { // if-None-Match:* => Do not write the response (304 not modified), // but write eTag header $needToSerializeResponse = false; } else { $eTag = $this->getETagForEntry($entryObject, $resourceType); // Note: The following code for attaching the prefix W\" // and the suffix " can be done in getETagForEntry function // but that is causing an issue in Linux env where the // firefix browser is unable to parse the ETag in this case. // Need to follow up PHP core devs for this. $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"'; if (!is_null($ifMatch)) { if (strcmp($eTag, $ifMatch) != 0) { // Requested If-Match value does not match with current // eTag Value then pre-condition error // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html throw ODataException::createPreConditionFailedError(Messages::eTagValueDoesNotMatch()); } } else { if (strcmp($eTag, $ifNoneMatch) == 0) { //304 not modified, but in write eTag header $needToSerializeResponse = false; } } } } } if (is_null($eTag)) { $eTag = $this->getETagForEntry($entryObject, $resourceType); // Note: The following code for attaching the prefix W\" // and the suffix " can be done in getETagForEntry function // but that is causing an issue in Linux env where the // firefix browser is unable to parse the ETag in this case. // Need to follow up PHP core devs for this. $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"'; } return $eTag; }