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;
    }