• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/composite/responder.php
  • Класс: BitrixMainCompositeResponder
  • Вызов: Responder::trySendResponse
static function trySendResponse()
{
	$cacheKey = self::getCacheKey();
	$cache = self::getHtmlCacheResponse($cacheKey);
	if ($cache === null || !$cache->exists())
	{
		return;
	}

	$compositeOptions = Helper::getOptions();

	$etag = $cache->getEtag();
	$lastModified = $cache->getLastModified();
	if ($etag !== false)
	{
		if (array_key_exists("HTTP_IF_NONE_MATCH", $_SERVER) && $_SERVER["HTTP_IF_NONE_MATCH"] === $etag)
		{
			self::setStatus("304 Not Modified");
			self::setHeaders($etag, false, "304");
			die();
		}
	}

	if ($lastModified !== false)
	{
		$sinceModified =
			isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) ?
			strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) :
			false;

		if ($sinceModified && $sinceModified >= $lastModified)
		{
			self::setStatus("304 Not Modified");
			self::setHeaders($etag, false, "304");
			die();
		}
	}

	$contents = $cache->getContents();
	if ($contents !== false)
	{
		self::setHeaders($etag, $lastModified, "200", $cache->getContentType());

		//compression support
		$compress = "";
		if ($compositeOptions["COMPRESS"] && isset($_SERVER["HTTP_ACCEPT_ENCODING"]))
		{
			if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "x-gzip") !== false)
			{
				$compress = "x-gzip";
			}
			elseif (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false)
			{
				$compress = "gzip";
			}
		}

		if ($compress)
		{
			header("Content-Encoding: ".$compress);
			echo $cache->isGzipped() ? $contents : gzencode($contents, 4);
		}
		else
		{
			if ($cache->isGzipped())
			{
				$contents = Helper::gzdecode($contents);
			}

			header("Content-Length: " . strlen($contents));
			echo $contents;
		}

		die();
	}
}