public function actionRead($resource_type, $id)
{
$ref = $this->getRef($resource_type, $id);
$vid = $ref->getVersionId();
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26
$etagMatch = null;
$modified = null;
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$etagMatch = false;
foreach (str_getcsv($_SERVER['HTTP_IF_NONE_MATCH']) as $tag) {
if ($tag == $vid || $tag == '*') {
$etagMatch = true;
break;
}
}
}
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$since = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ($since === false) {
$this->sendError("Failed to parse If-Modified-Since header: {$_SERVER['HTTP_IF_MODIFIED_SINCE']}");
}
$modified = $ref->getLastModified() > $since;
}
if ($etagMatch === null && $modified === false || $etagMatch === true && $modified !== true) {
$this->sendResponse(304);
}
header('Content-Location: ' . $this->createAbsoluteUrl('api/') . '/' . Yii::app()->service->referenceToFhirUrl($ref) . "/_history/{$vid}");
header("ETag: \"{$vid}\"");
$this->sendResource($ref->resolve());
}