86 $object->setContentType($data[
'content_type']);
88 $object->contentLength = (int) $data[
'bytes'];
89 $object->etag = (string) $data[
'hash'];
90 $object->lastModified = strtotime($data[
'last_modified']);
138 if (isset($headers[
'ETag'])) {
139 $headers[
'Etag'] = $headers[
'ETag'];
142 $object->setContentType($headers[
'Content-Type']);
143 $object->contentLength = empty($headers[
'Content-Length']) ? 0 : (int) $headers[
'Content-Length'];
144 $object->etag = (string) $headers[
'Etag'];
145 $object->lastModified = strtotime($headers[
'Last-Modified']);
153 if (!empty($headers[
'Content-Disposition'])) {
154 $object->setDisposition($headers[
'Content-Disposition']);
157 if (!empty($headers[
'Content-Encoding'])) {
158 $object->setEncoding($headers[
'Content-Encoding']);
197 $this->cdnSslUrl = $sslUrl;
234 public function url($cached = FALSE, $useSSL = TRUE) {
236 if ($cached && !empty($this->
cdnUrl)) {
237 return $useSSL ? $this->cdnSslUrl : $this->cdnUrl;
245 return parent::contentLength();
247 return $this->contentLength;
253 return parent::eTag();
266 return $this->lastModified;
271 return $this->metadata;
282 $this->allHeaders = array();
284 foreach ($headers as
$name => $value) {
286 $this->allHeaders[
$name] = $value;
306 return $this->allHeaders;
326 'etag' => TRUE,
'content-length' => TRUE,
327 'x-auth-token' => TRUE,
328 'transfer-encoding' => TRUE,
329 'x-trans-id' => TRUE,
341 foreach ($headers as
$name => $value) {
342 $lower = strtolower(
$name);
343 if (isset($this->reservedHeaders[$lower])) {
347 foreach ($unset as $u) {
377 foreach ($keys as
$key) {
378 unset($this->allHeaders[$key]);
472 public function stream($refresh = FALSE) {
476 if (!$refresh && isset($this->
content)) {
484 return $response->file();
496 $tmp = fopen(
'php://temp',
'rw');
526 $this->caching = $enabled;
541 return $this->caching;
572 $this->contentVerification = $enabled;
589 return $this->contentVerification;
624 if ($this->etag != md5($this->
content)) {
647 public function refresh($fetchContent = FALSE) {
676 $method = $fetchContent ?
'GET' :
'HEAD';
678 $client = \HPCloud\Transport::instance();
680 'X-Auth-Token' => $this->
token,
683 if (empty($this->
cdnUrl)) {
684 $response = $client->doRequest($this->
url, $method, $headers);
687 $response = $client->doRequest($this->
cdnUrl, $method, $headers);
690 if ($response->status() != 200) {
691 throw new \HPCloud\Exception(
'An unknown exception occurred during transmission.');
709 $this->
setContentType($response->header(
'Content-Type', $this->contentType()));
710 $this->
lastModified = strtotime($response->header(
'Last-Modified', 0));
711 $this->etag = $response->header(
'Etag', $this->etag);
712 $this->
contentLength = (int) $response->header(
'Content-Length', 0);
714 $this->
setDisposition($response->header(
'Content-Disposition', NULL));
715 $this->
setEncoding($response->header(
'Content-Encoding', NULL));