diff options
author | wei <> | 2006-01-06 22:21:07 +0000 |
---|---|---|
committer | wei <> | 2006-01-06 22:21:07 +0000 |
commit | 333eedb6eea18fdfb7bc0890cce1c30e6d44d363 (patch) | |
tree | 5b34d4181cd55e0219003d67d22a8438ac21b0d2 /framework/Web/THttpResponse.php | |
parent | 16660934cc48f357b1322bce7869158db2f7cb58 (diff) |
Diffstat (limited to 'framework/Web/THttpResponse.php')
-rw-r--r-- | framework/Web/THttpResponse.php | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index ecaf59d0..cf44d19d 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -32,6 +32,9 @@ * where {@link getCacheExpire CacheExpire}, {@link getCacheControl CacheControl}
* and {@link getBufferOutput BufferOutput} are configurable properties of THttpResponse.
*
+ * When sending headers the Charset set in {@link TGlobalization::getCharset()}
+ * is use when Charset is null or empty in THttpResponse.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web
@@ -59,6 +62,15 @@ class THttpResponse extends TModule implements ITextWriter * @var string HTML writer type
*/
private $_htmlWriterType='System.Web.UI.THtmlWriter';
+ /**
+ * @var string content type
+ */
+ private $_contentType='text/html';
+
+ /**
+ * @var string character set, e.g. UTF-8
+ */
+ private $_charset;
/**
* Destructor.
@@ -119,6 +131,38 @@ class THttpResponse extends TModule implements ITextWriter }
/**
+ * @string content type, default is text/html
+ */
+ public function setContentType($type)
+ {
+ $this->_contentType = $type;
+ }
+
+ /**
+ * @return string current content type
+ */
+ public function getContentType()
+ {
+ return $this->_contentType;
+ }
+
+ /**
+ * @return string output charset.
+ */
+ public function getCharset()
+ {
+ return $this->_charset;
+ }
+
+ /**
+ * @param string output charset.
+ */
+ public function setCharset($charset)
+ {
+ $this->_charset = $charset;
+ }
+
+ /**
* @return boolean whether to enable output buffer
*/
public function getBufferOutput()
@@ -226,13 +270,28 @@ class THttpResponse extends TModule implements ITextWriter }
/**
- * Outputs the buffered content.
+ * Outputs the buffered content, sends content-type and charset header.
*/
public function flush()
{
+ $header = $this->getContentTypeHeader();
+ $this->appendHeader($header);
if($this->_bufferOutput)
ob_flush();
- Prado::coreLog("Flushing output");
+ Prado::coreLog("Flushing output $header");
+ }
+
+ /**
+ * @return string content type and charset header
+ */
+ protected function getContentTypeHeader()
+ {
+ $app = $this->getApplication()->getGlobalization();
+ $charset = $this->getCharset();
+ if(empty($charset))
+ $charset = !is_null($app) ? $app->getCharset() : 'UTF-8';
+ $type = $this->getContentType();
+ return "Content-Type: $type; charset=$charset";
}
/**
@@ -254,6 +313,11 @@ class THttpResponse extends TModule implements ITextWriter header($value);
}
+ public function sendContentTypeHeader($type=null)
+ {
+
+ }
+
/**
* Writes a log message into error log.
* This method is simple wrapper of PHP function error_log.
|