This commit is contained in:
welefen 2013-12-20 23:33:05 +08:00
parent 161b0aef04
commit 7fc1d40c5c
4 changed files with 30 additions and 10 deletions

View File

@ -104,7 +104,7 @@ module.exports = Behavior(function(){
if (item) {
return item;
};
})
});
this.http.action = Dispatcher.getAction(pathname.pop());
this.http.controller = Dispatcher.getController(pathname.pop());
this.http.group = Dispatcher.getGroup(pathname.pop());

View File

@ -263,13 +263,7 @@ module.exports = Class(function(){
if (C('auto_send_content_type') && !this.http.cthIsSend) {
this.header("Content-Type", C("tpl_content_type"));
};
if (is_array(obj) || is_object(obj)) {
obj = JSON.stringify(obj);
};
if (!is_string(obj) && !(obj instanceof Buffer)) {
obj += "";
};
this.http.res.write(obj, encoding || C('encoding'));
this.http.echo(obj, encoding);
},
/**
* 结束输出输出完成时一定要调用这个方法

View File

@ -146,6 +146,7 @@ module.exports = Class(function(){
setHeader: function(name, value){
this.res.setHeader(name, value);
},
_cookie: {},
/**
* 设置cookie
* @param {[type]} name [description]
@ -153,6 +154,14 @@ module.exports = Class(function(){
* @param {[type]} options [description]
*/
setCookie: function(name, value, options){
if (name === true) {
var cookies = Object.values(this._cookie);
if (cookies.length) {
this.setHeader("Set-Cookie", cookies);
this._cookie = {};
};
return true;
};
options = options || {};
if (typeof options == 'number') {
options = {
@ -177,7 +186,7 @@ module.exports = Class(function(){
};
options = extend(defaultOptions, options || {});
value = cookie.serialize(name, value, options);
this.setHeader("Set-Cookie", value);
this._cookie[name] = value;
},
/**
* url跳转
@ -199,11 +208,28 @@ module.exports = Class(function(){
var time = Date.now() - this.startTime;
this.setHeader("X-" + name, time + "ms");
},
/**
* 输出内容
* @param {[type]} obj [description]
* @param {[type]} encoding [description]
* @return {[type]} [description]
*/
echo: function(obj, encoding){
this.setCookie(true);
if (is_array(obj) || is_object(obj)) {
obj = JSON.stringify(obj);
};
if (!is_string(obj) && !(obj instanceof Buffer)) {
obj += "";
};
this.res.write(obj, encoding || C('encoding'));
},
/**
* 结束URL
* @return {[type]} [description]
*/
end: function(){
this.setCookie(true);
tag("before_res_end", this);
this.res.end();
}

View File

@ -74,7 +74,7 @@ module.exports = Class(function(){
if (C('show_exec_time')) {
this.http.sendTime("Exec-Time");
};
this.http.res.write(content || "", C('encoding'));
this.http.echo(content || "", C('encoding'));
},
/**
* 获取模版文件内容