Cake\Network\Response::_setContentType PHP Method

_setContentType() protected method

Formats the Content-Type header based on the configured contentType and charset the charset will only be set in the header if the response is of type text/*
protected _setContentType ( ) : void
return void
    protected function _setContentType()
    {
        if (in_array($this->_status, [304, 204])) {
            return;
        }
        $whitelist = ['application/javascript', 'application/json', 'application/xml', 'application/rss+xml'];
        $charset = false;
        if ($this->_charset && (strpos($this->_contentType, 'text/') === 0 || in_array($this->_contentType, $whitelist))) {
            $charset = true;
        }
        if ($charset) {
            $this->header('Content-Type', "{$this->_contentType}; charset={$this->_charset}");
        } else {
            $this->header('Content-Type', "{$this->_contentType}");
        }
    }