mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-18 14:26:56 +00:00
Check headers is sent before set header
This commit is contained in:
parent
051ab23668
commit
2edcf33ca3
@ -1,5 +1,5 @@
|
||||
const helper = require('think-helper');
|
||||
|
||||
const debug = require('debug')('thinkjs');
|
||||
const deprecate = require('depd')('thinkjs');
|
||||
|
||||
/**
|
||||
@ -145,13 +145,19 @@ module.exports = {
|
||||
* @param {Mixed} value
|
||||
*/
|
||||
header(name, value){
|
||||
if(value === undefined && helper.isString(name)){
|
||||
return this.ctx.header[name];
|
||||
}
|
||||
if(this.ctx.res.headersSent){
|
||||
debug(`headers has already sent, url: ${this.ctx.url}`);
|
||||
return;
|
||||
}
|
||||
if(value !== undefined){
|
||||
return this.ctx.set(name, value);
|
||||
}
|
||||
if(helper.isObject(name)){
|
||||
return this.ctx.set(name);
|
||||
}
|
||||
return this.ctx.header[name];
|
||||
},
|
||||
/**
|
||||
* get userAgent header
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user