http: add response.headersSent property
Boolean property getter. True if headers was sent, false otherwise.
This commit is contained in:
parent
ac17dc1764
commit
b38277be26
@ -398,6 +398,10 @@ or
|
||||
|
||||
response.setHeader("Set-Cookie", ["type=ninja", "language=javascript"]);
|
||||
|
||||
### response.headersSent
|
||||
|
||||
Boolean (read-only). True if headers were sent, false otherwise.
|
||||
|
||||
### response.sendDate
|
||||
|
||||
When true, the Date header will be automatically generated and sent in
|
||||
|
@ -699,6 +699,12 @@ OutgoingMessage.prototype._renderHeaders = function() {
|
||||
};
|
||||
|
||||
|
||||
Object.defineProperty(OutgoingMessage.prototype, 'headersSent', {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function () { return !!this._header; }
|
||||
});
|
||||
|
||||
|
||||
OutgoingMessage.prototype.write = function(chunk, encoding) {
|
||||
if (!this._header) {
|
||||
|
@ -30,7 +30,9 @@ var s = http.createServer(function(req, res) {
|
||||
var contentType = 'Content-Type';
|
||||
var plain = 'text/plain';
|
||||
res.setHeader(contentType, plain);
|
||||
assert.ok(!res.headersSent);
|
||||
res.writeHead(200);
|
||||
assert.ok(res.headersSent);
|
||||
res.end('hello world\n');
|
||||
// This checks that after the headers have been sent, getHeader works
|
||||
// and does not throw an exception (Issue 752)
|
||||
|
Loading…
x
Reference in New Issue
Block a user