Express.js - 如何检查头文件是否已经发送? [英] Express.js - How to check if headers have already sent?
问题描述
简单:Connect的Response类提供了一个公共属性headerSent p>
res.headerSent
是一个布尔值,表示头文件是否已经发送到客户端。
从源代码:
/ **
*提供公共标头发送标志
*直到节点。
*
* @return {Boolean}
* @api public
* /
res .__ defineGetter __('headerSent',function(){
return this._header;
});
https://github.com/senchalabs/connect/blob/master/lib/patch.js#L22
I am writing a library which may set headers. I want to give a custom error message if headers have already sent, instead of just letting it fail with the "Can't set headers after they are sent" message given by Node.js. So how to check if headers have already sent?
Simple: Connect's Response class provides a public property "headerSent".
res.headerSent
is a boolean value that indicates whether the headers have already been sent to the client.
From the source code:
/**
* Provide a public "header sent" flag
* until node does.
*
* @return {Boolean}
* @api public
*/
res.__defineGetter__('headerSent', function(){
return this._header;
});
https://github.com/senchalabs/connect/blob/master/lib/patch.js#L22
这篇关于Express.js - 如何检查头文件是否已经发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!