Skip to content
Myr

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

5 files+8 added−19 removed

modified:lib/application.js+1 added-1 removed
136 unmodified lines
137 msg = escapeHtml(msg);138139 // 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 lines
modified:lib/patch.js-12 removed
modified:lib/response.js+3 added-3 removed
309 unmodified lines
310 done = true;311312 // clean up313 cleanup();314 if (!self.headerSent) self.removeHeader('Content-Disposition');314 if (!self.headersSent) self.removeHeader('Content-Disposition');315316 // callback available317 if (fn) return fn(err);318319 // list in limbo if there's no callback320 if (self.headerSent) return;320 if (self.headersSent) return;321322 // delegate323 next(err);324 }
26 unmodified lines
351 *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} path
411 unmodified lines
modified:test/res.sendfile.js+3 added-3 removed
40 unmodified lines
4142 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 lines
76 , calls = 0;7778 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 lines
94 , calls = 0;9596 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 lines
modified:History.md+1 added
13 unmodified lines
14 - `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