Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

http: add response.headersSent property

Boolean property getter. True if headers was sent, false otherwise.
  • Loading branch information...
commit b38277be266cfd6b6c3cc9e00730898f62a11f6e 1 parent ac17dc1
@langpavel langpavel authored bnoordhuis committed
View
4 doc/api/http.markdown
@@ -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
View
6 lib/http.js
@@ -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) {
View
2  test/simple/test-http-header-read.js
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.