Ejemplo n.º 1
0
 /**
  * @param Message\Request $request
  * @param Message\Response $response
  * @return static
  */
 public function register(Message\Request $request, Message\Response $response)
 {
     $type = $this->mime;
     $mtime = $this->statValue('mtime', time());
     $etag = $this->calcEtag();
     $fresh = $this->freshResponse($request, $mtime, $etag);
     $dispo = $this->disposition;
     $length = strlen($this->data);
     // Add common headers
     $response->getHeaders()->add('Etag', $etag)->add('Last-Modified', Message\Headers::date($mtime));
     if ($fresh) {
         // 200 OK
         $response->getHeaders()->add('Accept-Ranges', 'none')->add('Content-Type', $type)->add('Content-Length', $fresh ? $length : 0)->add('Content-Disposition', $dispo);
         $response->setBody($this->sendHandler());
     } else {
         // 304 Not Modified
         $response->setStatus(304)->setBody(null);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * @param Message\Request $request
  * @param Message\Response $response
  * @return static
  */
 public function register(Message\Request $request, Message\Response $response)
 {
     $info = pathinfo($this->filename);
     $mtime = $this->statValue('mtime', time());
     $etag = $this->fileEtag($this->filename);
     $fresh = $this->freshResponse($request, $mtime, $etag);
     $length = $this->statValue('size');
     // Add common headers
     $response->getHeaders()->add('Etag', $etag)->add('Last-Modified', Message\Headers::date($mtime));
     if ($fresh) {
         // 200 OK
         $headers = $response->getHeaders();
         $headers->add('Accept-Ranges', 'none')->add('Content-Type', $this->contentType($info))->add('Content-Disposition', $this->getDispoString());
         if ($fresh) {
             if ($length !== null) {
                 $headers->add('Content-Length', $length);
             }
         } else {
             $headers->add('Content-Length', 0);
         }
         $response->setBody($this->sendHandler());
         $this->autoclose = false;
     } else {
         // 304 Not Modified
         $response->setStatus(304)->setBody(null);
     }
     return $this;
 }