public function ensureSentHeaders()
    {
        if ($this->headers_sent) {
            return true;
        }
        if (isset($this->headers['STATUS'])) {
            $h = (isset($this->attrs->noHttpVer) && ($this->attrs->noHttpVer) ? 'Status: ' : $this->attrs->server['SERVER_PROTOCOL']) . ' ' . $this->headers['STATUS'] . "\r\n";
        } else {
            $h = '';
        }
        $http11 = $this->attrs->server['SERVER_PROTOCOL'] === 'HTTP/1.1';
        if ($this->contentLength === null
            && $this->upstream->checkChunkedEncCap()
            && $http11
        ) {
            $this->attrs->chunked = true;
        }
        if ($this->attrs->chunked) {
            $this->header('Transfer-Encoding: chunked');
        }

        if ($http11) {
            $connection = isset($this->attrs->server['HTTP_CONNECTION']) ? strtolower($this->attrs->server['HTTP_CONNECTION']) : 'keep-alive';
            if ($connection === 'keep-alive' && $this->upstream->getKeepaliveTimeout() > 0) {
                $this->header('Connection: keep-alive');
                $this->keepalive = true;
            } else {
                $this->header('Connection: close');
            }
        } else {
            $this->header('Connection: close');
        }

        foreach ($this->headers as $k => $line) {
            if ($k !== 'STATUS') {
                $h .= $line . "\r\n";
            }
        }
        $h .= "\r\n";
        $this->headers_sent_file = __FILE__;
        $this->headers_sent_line = __LINE__;
        $this->headers_sent = true;
        $this->upstream->requestOut($this, $h);
        return false;
    }