mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
nth try is the charm
This commit is contained in:
parent
5238e52575
commit
f95856f198
1 changed files with 19 additions and 14 deletions
|
@ -31,7 +31,6 @@ class Response
|
||||||
protected static $headersSent = false;
|
protected static $headersSent = false;
|
||||||
protected static $content = '';
|
protected static $content = '';
|
||||||
protected static $contentSent = false;
|
protected static $contentSent = false;
|
||||||
protected static $isHeadersOnly = false;
|
|
||||||
protected static $gzipResponseContent = true;
|
protected static $gzipResponseContent = true;
|
||||||
protected static $metaImages = [];
|
protected static $metaImages = [];
|
||||||
protected static $facebookAnalyticsType = "PageView";
|
protected static $facebookAnalyticsType = "PageView";
|
||||||
|
@ -145,8 +144,21 @@ class Response
|
||||||
|
|
||||||
public static function send()
|
public static function send()
|
||||||
{
|
{
|
||||||
|
$status = static::getHeader(static::HEADER_STATUS);
|
||||||
|
$sendContent = true;
|
||||||
|
if ((!$status || $status === 200) &&
|
||||||
|
static::getHeader(static::HEADER_ETAG) &&
|
||||||
|
Request::getHttpHeader('If-None-Match', null) === static::getHeader(static::HEADER_ETAG)
|
||||||
|
) {
|
||||||
|
static::setHeader(static::HEADER_STATUS, 304);
|
||||||
|
$sendContent = false;
|
||||||
|
}
|
||||||
|
|
||||||
static::sendHeaders();
|
static::sendHeaders();
|
||||||
static::sendContent();
|
|
||||||
|
if ($sendContent) {
|
||||||
|
static::sendContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setContent(string $content)
|
public static function setContent(string $content)
|
||||||
|
@ -165,18 +177,11 @@ class Response
|
||||||
throw new LogicException('Content has already been sent. It cannot be sent twice');
|
throw new LogicException('Content has already been sent. It cannot be sent twice');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!static::$isHeadersOnly) {
|
echo static::$content;
|
||||||
echo static::$content;
|
|
||||||
}
|
|
||||||
|
|
||||||
static::$contentSent = true;
|
static::$contentSent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setIsHeadersOnly(bool $isHeadersOnly = true)
|
|
||||||
{
|
|
||||||
static::$isHeadersOnly = $isHeadersOnly;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function setDownloadHttpHeaders($name, $type = null, $size = null, $noSniff = true)
|
public static function setDownloadHttpHeaders($name, $type = null, $size = null, $noSniff = true)
|
||||||
{
|
{
|
||||||
static::setBinaryHttpHeaders($type, $size, $noSniff);
|
static::setBinaryHttpHeaders($type, $size, $noSniff);
|
||||||
|
@ -196,20 +201,20 @@ class Response
|
||||||
//public immutable cache = hard-caching (no server checks) until time limit passes
|
//public immutable cache = hard-caching (no server checks) until time limit passes
|
||||||
public static function enablePublicImmutableCache(int $seconds = 300)
|
public static function enablePublicImmutableCache(int $seconds = 300)
|
||||||
{
|
{
|
||||||
static::setHeader(static::HEADER_CACHE_CONTROL, 'public, max-age=' . $seconds);
|
static::setHeader(static::HEADER_CACHE_CONTROL, 'public, max-age=' . $seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
//public mutable cache = soft-caching (requires at least one round trip for headers) as long as etag identifier matches
|
//public mutable cache = soft-caching (requires at least one round trip for headers) as long as etag identifier matches
|
||||||
public static function enablePublicMutableCache(string $etag)
|
public static function enablePublicMutableCache(string $etag)
|
||||||
{
|
{
|
||||||
static::setHeader(static::HEADER_CACHE_CONTROL, 'public, no-cache');
|
static::setHeader(static::HEADER_CACHE_CONTROL, 'public');
|
||||||
static::setHeader(static::HEADER_ETAG, $etag);
|
static::setHeader(static::HEADER_ETAG, $etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
//always reload and re-execute this resource, disable any local or intermediary caching
|
//always reload and re-execute this resource, disable any local or intermediary caching
|
||||||
public static function disableHttpCache()
|
public static function disableHttpCache()
|
||||||
{
|
{
|
||||||
static::setHeader(static::HEADER_CACHE_CONTROL, 'private, no-cache, no-store');
|
static::setHeader(static::HEADER_CACHE_CONTROL, 'private, no-cache, no-store');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setHeader($name, $value)
|
public static function setHeader($name, $value)
|
||||||
|
|
Loading…
Add table
Reference in a new issue