Example #1
0
 /**
  * Finalize response for delivery to client
  *
  * Apply final preparations to the resposne object
  * so that it is suitable for delivery to the client.
  *
  * @param  \Slim\Interfaces\Http\RequestInterface $request
  * @return \Slim\Interfaces\Http\Response Self
  * @api
  */
 public function finalize(\Slim\Interfaces\Http\RequestInterface $request)
 {
     $sendBody = true;
     if (in_array($this->status, array(204, 304)) === true) {
         $this->headers->remove('Content-Type');
         $this->headers->remove('Content-Length');
         $sendBody = false;
     } else {
         $size = @$this->getSize();
         if ($size) {
             $this->headers->set('Content-Length', $size);
         }
     }
     // Serialize cookies into HTTP header
     $this->cookies->setHeaders($this->headers);
     // Remove body if HEAD request
     if ($request->isHead() === true) {
         $sendBody = false;
     }
     // Truncate body if it should not be sent with response
     if ($sendBody === false) {
         $this->body->close();
         $this->body = new \Guzzle\Stream\Stream(fopen('php://temp', 'r+'));
     }
     return $this;
 }