From 0e53d6ec7b706d71b83230aa0165ec19a2cc10b7 Mon Sep 17 00:00:00 2001 From: rojaro <> Date: Tue, 18 May 2010 09:10:39 +0000 Subject: By default getContentType() now only returns the mimetype --- framework/Web/THttpRequest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index ed981c90..fbceef38 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -319,11 +319,18 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar } /** - * @return string content type (e.g. 'application/json') or null if not specified + * @param boolean $mimetypeOnly whether to return only the mimetype (default: true) + * @return string content type (e.g. 'application/json' or 'text/html; encoding=gzip') or null if not specified */ - public function getContentType() + public function getContentType($mimetypeOnly = true) { - return isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : null; + if(!isset($_SERVER['CONTENT_TYPE'])) + return null; + + if($mimetypeOnly === true && ($_pos = strpos(';', $_SERVER['CONTENT_TYPE'])) !== false) + return substr($_SERVER['CONTENT_TYPE'], 0, $_pos); + + return $_SERVER['CONTENT_TYPE']; } /** -- cgit v1.2.3