Changeset View
Changeset View
Standalone View
Standalone View
src/aphront/response/AphrontResponse.php
| <?php | <?php | ||||
| abstract class AphrontResponse extends Phobject { | abstract class AphrontResponse extends Phobject { | ||||
| private $request; | private $request; | ||||
| private $cacheable = false; | private $cacheable = false; | ||||
| private $canCDN; | |||||
| private $responseCode = 200; | private $responseCode = 200; | ||||
| private $lastModified = null; | private $lastModified = null; | ||||
| protected $frameable; | protected $frameable; | ||||
| public function setRequest($request) { | public function setRequest($request) { | ||||
| $this->request = $request; | $this->request = $request; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | public function getHeaders() { | ||||
| return $headers; | return $headers; | ||||
| } | } | ||||
| public function setCacheDurationInSeconds($duration) { | public function setCacheDurationInSeconds($duration) { | ||||
| $this->cacheable = $duration; | $this->cacheable = $duration; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setCanCDN($can_cdn) { | |||||
| $this->canCDN = $can_cdn; | |||||
| return $this; | |||||
| } | |||||
| public function setLastModified($epoch_timestamp) { | public function setLastModified($epoch_timestamp) { | ||||
| $this->lastModified = $epoch_timestamp; | $this->lastModified = $epoch_timestamp; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setHTTPResponseCode($code) { | public function setHTTPResponseCode($code) { | ||||
| $this->responseCode = $code; | $this->responseCode = $code; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | protected function addJSONShield($json_response) { | ||||
| $response = $shield.$json_response; | $response = $shield.$json_response; | ||||
| return $response; | return $response; | ||||
| } | } | ||||
| public function getCacheHeaders() { | public function getCacheHeaders() { | ||||
| $headers = array(); | $headers = array(); | ||||
| if ($this->cacheable) { | if ($this->cacheable) { | ||||
| if ($this->canCDN) { | |||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Expires', | 'Cache-Control', | ||||
| $this->formatEpochTimestampForHTTPHeader(time() + $this->cacheable), | 'public', | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Cache-Control', | 'Cache-Control', | ||||
| 'private, no-cache, no-store, must-revalidate', | 'private', | ||||
| ); | |||||
| } | |||||
| $headers[] = array( | |||||
| 'Expires', | |||||
| $this->formatEpochTimestampForHTTPHeader(time() + $this->cacheable), | |||||
| ); | ); | ||||
| } else { | |||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Pragma', | 'Cache-Control', | ||||
| 'no-cache', | 'no-store', | ||||
| ); | ); | ||||
| $headers[] = array( | $headers[] = array( | ||||
| 'Expires', | 'Expires', | ||||
| 'Sat, 01 Jan 2000 00:00:00 GMT', | 'Sat, 01 Jan 2000 00:00:00 GMT', | ||||
| ); | ); | ||||
| } | } | ||||
| if ($this->lastModified) { | if ($this->lastModified) { | ||||
| Show All 25 Lines | |||||