mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
fix #3. auto send content-type header.
This commit is contained in:
parent
400f8b176e
commit
48613b7f0b
@ -27,6 +27,7 @@ module.exports = {
|
||||
deny_remote_access_by_ip: true, //禁止通过外网的IP直接访问
|
||||
url_callback_name: "callback", //jsonp格式的callback名字
|
||||
json_content_type: "application/json",
|
||||
auto_send_content_type: true, //是否自动发送Content-Type,默认值为`tpl_content_type`配置值
|
||||
|
||||
cookie_domain: "", //cookie有效域名
|
||||
cookie_path: "", //cookie路径
|
||||
|
||||
@ -214,7 +214,9 @@ module.exports = Class(function(){
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
json: function(data, jsonp){
|
||||
this.header("Content-Type", C("json_content_type"));
|
||||
this.header("Content-Type", C("json_content_type") + ";charset=" + C("charset"));
|
||||
//标记content-type的header已经发送
|
||||
this.http.sendContentType = true;
|
||||
var callback = this.get(C("url_callback_name"));
|
||||
callback = callback.replace(/[^\w\.]/g, "");
|
||||
if (jsonp && callback) {
|
||||
@ -233,6 +235,11 @@ module.exports = Class(function(){
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
echo: function(obj, encoding){
|
||||
//自动发送Content-Type的header
|
||||
if (C('auto_send_content_type') && !this.http.sendContentType) {
|
||||
this.header("Content-Type", C("tpl_content_type") + ";charset=" + C("charset"));
|
||||
this.http.sendContentType = true;
|
||||
};
|
||||
if (is_array(obj) || is_object(obj)) {
|
||||
obj = JSON.stringify(obj);
|
||||
};
|
||||
|
||||
@ -27,7 +27,7 @@ module.exports = Class(function(){
|
||||
content = this.fetch(templateFile, content);
|
||||
this.render(content, charset, contentType);
|
||||
tag("view_end", this.http);
|
||||
this.http.res.end();
|
||||
this.http.end();
|
||||
},
|
||||
render: function(content, charset, contentType){
|
||||
if (charset === undefined) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user