public function output()
    {
        if ($this->status === null) {
            $this->status = (empty($this->body) || $this->method === 'HEAD')
                ? HttpResponse::HTTP_NO_CONTENT
                : HttpResponse::HTTP_OK;
        }

        if ($this->method === 'HEAD'
            || !HttpResponse::canHaveBody($this->status)
        ) {
            $content_type = 'HEAD';
        } elseif (is_array($this->body)) {
            $content_type = 'application/json';
        } else {
            $content_type = $this->headers['Content-Type'] ?? null;
        }

        Utils::checkOutput($content_type);

        if ($this->zlib_compression && $content_type !== 'HEAD') {
            ini_set('zlib.output_compression', 1);
        }

        header(HttpResponse::getHeader($this->status));
        foreach ($this->headers as $key => $value) {
            header("$key: " . implode(',', (array) $value));
        }

        if ($content_type !== 'HEAD') {
            if (is_array($this->body)) {
                echo json_encode($this->body, JSON_PRETTY_PRINT);
            } else {
                echo $this->body;
            }
        }
    }