Output http headers suitable for xmlhttp

@param string $contenttype Content-type to output
@param string $charset Charset of content
434816
static function sendXmlHttpResponseHeaders($contenttype = "application/json", $charset = 'utf-8')
	{
		if ( is_null($charset) )
			$charset = mb_internal_encoding();
			
		// charset
		header("Content-Type: $contenttype; charset=$charset");
		
		// no cache
		header("Expires: Sat, 1 Jan 2005 00:00:00 GMT");
		header("Last-Modified: ".gmdate( "D, d M Y H:i:s")." GMT");
		header("Cache-Control: no-cache, must-revalidate");
		header("Pragma: no-cache");	
	}
257922
public void doHttpPut(String url, HttpResponse result, Map<String, Object> headers, String contentType) {
        httpClient.put(url, result, headers, contentType);
    }
134911
public function setContentType(string $contentType, string $charset = null)
    {
        $this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));

        return $this;
    }
255105
public function setCharset($charset)
    {
        $this->charset = $charset;
        if (!$this->headerCharset) {
            $this->headerCharset = $charset;
        }

        return $this;
    }
266136
public function setContentType($type, $charset=''){
        if(headers_sent()) return;
        if(empty($charset))  $charset = C('DEFAULT_CHARSET');
        $type = strtolower($type);
        if(isset($this->allowOutputType[$type])) //过滤content_type
            header('Content-Type: '.$this->allowOutputType[$type].'; charset='.$charset);
    }
583565
public static String addCharset(String charset, String contentType)
    {
        if (null == contentType)
        {
            return "text/plain;charset=" + charset;
        }
        else
        {
            Matcher matcher = CHARSET_PATT.matcher(contentType);
            if (matcher.find())
            {
                // replace what ever content-type with the charset
                return contentType.substring(0, matcher.start(1)) +
                    charset + contentType.substring(matcher.end(1));
            }
            else
            {
                return contentType + ";charset=" + charset;
            }
        }
    }
636377
public function setContentType($contentType, $charset=NULL){
        $this->setHeader("Content-Type", $contentType);
        if($charset != NULL){
            $this->setHeader("charset", $charset);
        }
    }
763919
public function print(
        string $str,
        string $contentType = null
    ): ResponseInterface
    {
        $body = Factory::streamFromFile('php://temp', 'wb+');
        $body->write($str);
        $body->rewind();

        if ($contentType) {
            $this->header->set('Content-Type', $contentType);
        }

        return $this->setStatus(200)->response($body);
    }
1121568
public function setContentType($contentType, $charset = null)
    {
        if ($charset === null) {
            $this->setHeader('Content-Type', $contentType);
        } else {
            $this->setHeader('Content-Type', $contentType . '; charset=' . $charset);
        }

        return $this;
    }
1355941
public function withContentType($contentType)
    {
        $contentType = $this->normalizeContentType($contentType);

        $contentType = explode(';', $contentType, 2);

        $this->type = $contentType[0];

        $contentType[0] .= ';' . (isset($contentType[1]) ? $contentType[1] : ' charset=utf-8');

        return $this->withHeader('Content-Type', $contentType[0]);
    }
204659
function setContentType($mime_type, $charset='utf-8') {
		
		$header = 'Content-Type: ' . $mime_type;
		if ($charset) {
			$header .= '; charset='.$charset;
		}
		
		$this->headers[] = array($header, TRUE);
		
		return $this;
	}
111571
public function setContentType($mimeType, $charset = null)
    {
        static $mimes = [];

        if (empty($mimes)) {
            $mimes = require(str_replace('Http', 'Config', __DIR__) . DIRECTORY_SEPARATOR . 'Mimes.php');
        }

        if (strpos($mimeType, '/') === false) {
            $extension = ltrim($mimeType, '.');
            // Is this extension supported?
            if (isset($mimes[ $extension ])) {
                $mimeType =& $mimes[ $extension ];
                if (is_array($mimeType)) {
                    $mimeType = current($mimeType);
                }
            }
        }

        $this->mimeType = $mimeType;

        $this->addHeader(
            'Content-Type',
            $mimeType
            . (empty($charset) ? '' : '; charset=' . $charset)
        );

        return $this;
    }
570232
public function setContentType($contentType)
    {
        $allowedTypes = array(
            'text/html',
            'text/xml',
            'text/htmlraw',
            'text/raw'
        );

        if (!in_array(strtolower($contentType), $allowedTypes)) {
            throw new \InvalidArgumentException(
                "Illegal content type, allowed content types are " . implode(', ', $allowedTypes)
            );
        }
        $this->contentType = $contentType;

        return $this;
    }
482332
protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
        $this->view->display($templateFile,$charset,$contentType,$content,$prefix);
    }
947429
function serialize($charset_encoding='')
		{
			if ($charset_encoding != '')
				$this->content_type = 'text/xml; charset=' . $charset_encoding;
			else
				$this->content_type = 'text/xml';
			if ($GLOBALS['xmlrpc_null_apache_encoding'])
			{
				$result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";
			}
			else
			{
			$result = "<methodResponse>\n";
			}
			if($this->errno)
			{
				// G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients
				// by xml-encoding non ascii chars
				$result .= "<fault>\n" .
"<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
"</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $charset_encoding) . "</string></value>\n</member>\n" .
"</struct>\n</value>\n</fault>";
			}
			else
			{
				if(!is_object($this->val) || !is_a($this->val, 'xmlrpcval'))
				{
					if (is_string($this->val) && $this->valtyp == 'xml')
					{
						$result .= "<params>\n<param>\n" .
							$this->val .
							"</param>\n</params>";
					}
					else
					{
						/// @todo try to build something serializable?
						die('cannot serialize xmlrpcresp objects whose content is native php values');
					}
				}
				else
				{
					$result .= "<params>\n<param>\n" .
						$this->val->serialize($charset_encoding) .
						"</param>\n</params>";
				}
			}
			$result .= "\n</methodResponse>";
			$this->payload = $result;
			return $result;
		}
75287
protected function _headers($options, $mime, $charset, $encoding, $length)
    {
        $headers = !empty($options['headers']) ? $options['headers'] : [];

        if (!empty($options['disposition'])) {
            $parts = [$options['disposition']];
            foreach (['name', 'filename'] as $name) {
                if (!empty($options[$name])) {
                    $value = htmlspecialchars_decode(htmlspecialchars($options[$name], ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
                    $value = preg_replace('~[\s/\\\]~', '', $value);
                    $value = addcslashes($value, '"');
                    $parts[] = "{$name}=\"{$value}\"";
                }
            }
            $headers[] = "Content-Disposition: " . join('; ', $parts);
        }

        if (!empty($options['id'])) {
            $headers[] = 'Content-ID: ' . $options['id'];
        }

        if (!empty($mime)) {
            $charset = $charset ? '; charset=' . $charset : '';
            $headers[] = 'Content-Type: ' . $mime . $charset;
        }

        if (!empty($encoding)) {
            $headers[] = 'Content-Transfer-Encoding: ' . $encoding;
        }

        if (!empty($options['length'])) {
            $headers[] = 'Content-Length: ' . $length;
        }

        if (!empty($options['description'])) {
            $headers[] = 'Content-Description: ' . $options['description'];
        }

        if (!empty($options['location'])) {
            $headers[] = 'Content-Location: ' . $options['location'];
        }

        if (!empty($options['language'])) {
            $headers[] = 'Content-Language: ' . $options['language'];
        }
        return $headers;
    }
771354
public function setCharset($charset)
    {
        $this->charset = $charset;
        $this->setContentType($this->getContentType()); // update charset which is set on content-type

        return $this;
    }