remove ServerResonse.headerSent monkey patch
Before adoption: this commit came in with the history the project adopted, so no landing records it.
node.js ServerResponse contains a headersSent field. Use that instead of our patched misnamed version.
authored by Roman Shtylman · committed by Roman Shtylman · parent 1396e08 · Browse files · 5 files·+8 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+8 added−19 removed
- tests:+3 added−3 removed
- other:+5 added−16 removed
Provenance
- Commit
6835289- Tree
a892c15- Author
Roman Shtylman <shtylman@gmail.com>- Committer
Roman Shtylman <shtylman@gmail.com>- Parent
1396e08
5 files changed+8 added−19 removed
modified:lib/application.js+1 added-1 removed
136 unmodified lines137 msg = escapeHtml(msg);138 139 // log to stderr in a non-test env140 if ('test' != env) console.error(err.stack || err.toString());141- if (res.headerSent) return req.socket.destroy();141+ if (res.headersSent) return req.socket.destroy();142 res.setHeader('Content-Type', 'text/html');143 res.setHeader('Content-Length', Buffer.byteLength(msg));144 if ('HEAD' == req.method) return res.end();145 res.end(msg);394 unmodified linesmodified:lib/patch.js-12 removed
19 unmodified lines202122232425262728293031323334352425262740 unmodified lines19 unmodified linesvar setHeader = ServerResponse.prototype.setHeader;var writeHead = ServerResponse.prototype.writeHead;
/** * Provide a public "header sent" flag * until node does. * * @return {Boolean} * @api public */
ServerResponse.prototype.__defineGetter__('headerSent', function(){ return this._header;});
/** * Set header `field` to `val`, special-casing * the `Set-Cookie` field for multiple support. * * @param {String} field40 unmodified linesmodified:lib/response.js+3 added-3 removed
309 unmodified lines310 done = true;311 312 // clean up313 cleanup();314- if (!self.headerSent) self.removeHeader('Content-Disposition');314+ if (!self.headersSent) self.removeHeader('Content-Disposition');315 316 // callback available317 if (fn) return fn(err);318 319 // list in limbo if there's no callback320- if (self.headerSent) return;320+ if (self.headersSent) return;321 322 // delegate323 next(err);324 }26 unmodified lines351 *352 * Optionally providing an alternate attachment `filename`,353 * and optional callback `fn(err)`. The callback is invoked354 * when the data transfer is complete, or when an error has355- * ocurred. Be sure to check `res.headerSent` if you plan to respond.355+ * ocurred. Be sure to check `res.headersSent` if you plan to respond.356 *357 * This method uses `res.sendfile()`.358 *359 * @param {String} path411 unmodified linesmodified:test/res.sendfile.js+3 added-3 removed
40 unmodified lines41 42 app.use(function(req, res){43 res.sendfile('test/fixtures/nope.html', function(err){44 ++calls;45- assert(!res.headerSent);45+ assert(!res.headersSent);46 res.send(err.message);47 });48 });49 26 unmodified lines76 , calls = 0;77 78 app.use(function(req, res){79 res.sendfile('test/fixtures/foo/../user.html', function(err){80- assert(!res.headerSent);80+ assert(!res.headersSent);81 ++calls;82 res.send(err.message);83 });84 });9 unmodified lines94 , calls = 0;95 96 app.use(function(req, res){97 res.sendfile('test/fixtures/user.html', function(err){98- assert(!res.headerSent);98+ assert(!res.headersSent);99 req.socket.listeners('error').should.have.length(1); // node's original handler100 done();101 });102 140 unmodified linesmodified:History.md+1 added
13 unmodified lines14 - `json spaces` no longer enabled by default in development15 - `req.accepts*` -> `req.accepts*s` - i.e. `req.acceptsEncoding` -> `req.acceptsEncodings`16 - `req.params` is now an object instead of an array17 - `res.locals` is no longer a function. It is a plain js object. Treat it as such.18+ - `res.headerSent` -> `res.headersSent` to match node.js ServerResponse object19 * refactor:20 - `req.accepts*` with [accepts](https://github.com/expressjs/accepts)21 - `req.is` with [type-is](https://github.com/expressjs/type-is)22 * add:1256 unmodified lines