public function buildHeaders()
    {
        if ($this->use_cors) {
            if (strlen($this->cors_allow_origin) > 0) {
                header("Access-Control-Allow-Origin: $this->cors_allow_origin");
            }
            if ($this->cors_with_credentials) {
                header('Access-Control-Allow-Credentials: true');
            } else {
                header('Access-Control-Allow-Credentials: false');
            }
        }

        // Cache Control RFC: https://tools.ietf.org/html/rfc7234
        if ($this->nb_request instanceof CNabuHTTPRequest &&
            ($nb_site_target = $this->nb_request->getSiteTarget()) instanceof CNabuSiteTarget
        ) {
            if (($max_age = $nb_site_target->getDynamicCacheEffectiveMaxAge()) !== false) {
                $expire_date = gmdate("D, d M Y H:i:s", time() + $max_age);
                $this->setHeader('Expires', $expire_date . 'GMT');
                $this->setHeader('Cache-Control', "max-age=$max_age");
                $this->setHeader('User-Cache-Control', "max-age=$max_age");
                $this->setHeader('Pragma', 'cache');
            } else {
                $this->setHeader('Expires', 'Thu, 1 Jan 1981 00:00:00 GMT');
                $this->setheader('Cache-Control', 'no-store, no-cache, must-revalidate');
                $this->setHeader('Pragma', 'no-cache');
            }
            if ($nb_site_target->getAttachment() === 'T') {
                if (is_string($this->attachment_filename) && strlen($this->attachment_filename) > 0) {
                    $this->setHeader('Content-Disposition', 'attachment; filename=' . $this->attachment_filename);
                } else {
                    $this->setHeader('Content-Disposition', 'attachment');
                }
            }
        }

        if (($frame_options = $this->calculateFrameOptions()) !== null) {
            $this->setHeader('X-Frame-Options', $frame_options);
        }

        if (count($this->header_list) > 0) {
            foreach ($this->header_list as $name => $value) {
                header("$name: $value");
            }
        }
    }