public function flushHeaders($global = true) {
        if (headers_sent()) {
            return;
        }

        if ($global) {
            $cookies = array_replace(static::globalCookies(), $this->cookies);
            $headers = array_replace(static::globalHeaders(), $this->headers);
        } else {
            $cookies = $this->cookies;
            $headers = $this->headers;
        }

        // Set the cookies first.
        foreach ($cookies as $name => $value) {
            setcookie(
                $name,
                $value[0],
                $value[1],
                $value[2] !== null ? $value[2] : $this->defaultCookiePath,
                $value[3] !== null ? $value[3] : $this->defaultCookieDomain,
                $value[4],
                $value[5]
            );
        }

        // Set the response code.
        header(static::statusMessage($this->status, true), true, $this->status);

        $headers = array_filter($headers);

        // The content type is a special case.
        if (isset($headers['Content-Type'])) {
            $contentType = (array)$headers['Content-Type'];
            header('Content-Type: '.reset($contentType).'; charset=utf8', true);
            unset($headers['Content-Type']);
        }

        // Flush the rest of the headers.
        foreach ($headers as $name => $value) {
            foreach ((array)$value as $hvalue) {
                header("$name: $hvalue", false);
            }
        }
    }