deps: on-finished@2.4.1
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 980d881 · Browse files · 4 files·+205 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+205 added−1 removed
- tests:+202 added−0 removed
- other:+3 added−1 removed
Provenance
- Commit
2e2d78c- Tree
9901db6- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
980d881
4 files changed+205 added−1 removed
modified:test/res.download.js+73 added
1 'use strict'2 3 var after = require('after');4+var assert = require('assert')5+var asyncHooks = tryRequire('async_hooks')6 var Buffer = require('safe-buffer').Buffer7 var express = require('..');8 var path = require('path')9 var request = require('supertest');10 var utils = require('./support/utils')11 12 var FIXTURES_PATH = path.join(__dirname, 'fixtures')13 14+var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'15+ ? describe16+ : describe.skip17+18 describe('res', function(){19 describe('.download(path)', function(){20 it('should transfer as an attachment', function(done){21 var app = express();67 unmodified lines89 .expect('Content-Type', 'text/html; charset=UTF-8')90 .expect('Content-Disposition', 'attachment; filename="user.html"')91 .expect(200, cb);92 })93+94+ describeAsyncHooks('async local storage', function () {95+ it('should presist store', function (done) {96+ var app = express()97+ var cb = after(2, done)98+ var store = { foo: 'bar' }99+100+ app.use(function (req, res, next) {101+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()102+ req.asyncLocalStorage.run(store, next)103+ })104+105+ app.use(function (req, res) {106+ res.download('test/fixtures/name.txt', function (err) {107+ if (err) return cb(err)108+109+ var local = req.asyncLocalStorage.getStore()110+111+ assert.strictEqual(local.foo, 'bar')112+ cb()113+ })114+ })115+116+ request(app)117+ .get('/')118+ .expect('Content-Type', 'text/plain; charset=UTF-8')119+ .expect('Content-Disposition', 'attachment; filename="name.txt"')120+ .expect(200, 'tobi', cb)121+ })122+123+ it('should presist store on error', function (done) {124+ var app = express()125+ var store = { foo: 'bar' }126+127+ app.use(function (req, res, next) {128+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()129+ req.asyncLocalStorage.run(store, next)130+ })131+132+ app.use(function (req, res) {133+ res.download('test/fixtures/does-not-exist', function (err) {134+ var local = req.asyncLocalStorage.getStore()135+136+ if (local) {137+ res.setHeader('x-store-foo', String(local.foo))138+ }139+140+ res.send(err ? 'got ' + err.status + ' error' : 'no error')141+ })142+ })143+144+ request(app)145+ .get('/')146+ .expect(200)147+ .expect('x-store-foo', 'bar')148+ .expect('got 404 error')149+ .end(done)150+ })151+ })152 })153 154 describe('.download(path, options)', function () {155 it('should allow options to res.sendFile()', function (done) {331 unmodified lines487 .expect(200, 'failed', done)488 })489 })490 })491+492+function tryRequire (name) {493+ try {494+ return require(name)495+ } catch (e) {496+ return {}497+ }498+}modified:test/res.sendFile.js+129 added
1 'use strict'2 3 var after = require('after');4+var asyncHooks = tryRequire('async_hooks')5 var Buffer = require('safe-buffer').Buffer6 var express = require('../')7 , request = require('supertest')8 , assert = require('assert');1 unmodified line10 var path = require('path');11 var fixtures = path.join(__dirname, 'fixtures');12 var utils = require('./support/utils');13 14+var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'15+ ? describe16+ : describe.skip17+18 describe('res', function(){19 describe('.sendFile(path)', function () {20 it('should error missing path', function (done) {21 var app = createApp();243 unmodified lines265 request(app)266 .get('/')267 .expect(200, 'got 404 error', done)268 })269+270+ describeAsyncHooks('async local storage', function () {271+ it('should presist store', function (done) {272+ var app = express()273+ var cb = after(2, done)274+ var store = { foo: 'bar' }275+276+ app.use(function (req, res, next) {277+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()278+ req.asyncLocalStorage.run(store, next)279+ })280+281+ app.use(function (req, res) {282+ res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) {283+ if (err) return cb(err)284+285+ var local = req.asyncLocalStorage.getStore()286+287+ assert.strictEqual(local.foo, 'bar')288+ cb()289+ })290+ })291+292+ request(app)293+ .get('/')294+ .expect('Content-Type', 'text/plain; charset=UTF-8')295+ .expect(200, 'tobi', cb)296+ })297+298+ it('should presist store on error', function (done) {299+ var app = express()300+ var store = { foo: 'bar' }301+302+ app.use(function (req, res, next) {303+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()304+ req.asyncLocalStorage.run(store, next)305+ })306+307+ app.use(function (req, res) {308+ res.sendFile(path.resolve(fixtures, 'does-not-exist'), function (err) {309+ var local = req.asyncLocalStorage.getStore()310+311+ if (local) {312+ res.setHeader('x-store-foo', String(local.foo))313+ }314+315+ res.send(err ? 'got ' + err.status + ' error' : 'no error')316+ })317+ })318+319+ request(app)320+ .get('/')321+ .expect(200)322+ .expect('x-store-foo', 'bar')323+ .expect('got 404 error')324+ .end(done)325+ })326+ })327 })328 329 describe('.sendFile(path, options)', function () {330 it('should pass options to send module', function (done) {730 unmodified lines1061 request(app)1062 .get('/')1063 .end(function(){});1064 })1065+1066+ describeAsyncHooks('async local storage', function () {1067+ it('should presist store', function (done) {1068+ var app = express()1069+ var cb = after(2, done)1070+ var store = { foo: 'bar' }1071+1072+ app.use(function (req, res, next) {1073+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()1074+ req.asyncLocalStorage.run(store, next)1075+ })1076+1077+ app.use(function (req, res) {1078+ res.sendfile('test/fixtures/name.txt', function (err) {1079+ if (err) return cb(err)1080+1081+ var local = req.asyncLocalStorage.getStore()1082+1083+ assert.strictEqual(local.foo, 'bar')1084+ cb()1085+ })1086+ })1087+1088+ request(app)1089+ .get('/')1090+ .expect('Content-Type', 'text/plain; charset=UTF-8')1091+ .expect(200, 'tobi', cb)1092+ })1093+1094+ it('should presist store on error', function (done) {1095+ var app = express()1096+ var store = { foo: 'bar' }1097+1098+ app.use(function (req, res, next) {1099+ req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()1100+ req.asyncLocalStorage.run(store, next)1101+ })1102+1103+ app.use(function (req, res) {1104+ res.sendfile('test/fixtures/does-not-exist', function (err) {1105+ var local = req.asyncLocalStorage.getStore()1106+1107+ if (local) {1108+ res.setHeader('x-store-foo', String(local.foo))1109+ }1110+1111+ res.send(err ? 'got ' + err.status + ' error' : 'no error')1112+ })1113+ })1114+1115+ request(app)1116+ .get('/')1117+ .expect(200)1118+ .expect('x-store-foo', 'bar')1119+ .expect('got 404 error')1120+ .end(done)1121+ })1122+ })1123 })1124 1125 describe('.sendfile(path)', function(){1126 it('should not serve dotfiles', function(done){273 unmodified lines1400 });1401 1402 return app;1403 }1404+1405+function tryRequire (name) {1406+ try {1407+ return require(name)1408+ } catch (e) {1409+ return {}1410+ }1411+}modified:History.md+2 added
24 unmodified lines25 * deps: finalhandler@1.2.026 - Remove set content headers that break response27 - deps: on-finished@2.4.128 - deps: statuses@2.0.129+ * deps: on-finished@2.4.130+ - Prevent loss of async hooks context31 * deps: qs@6.10.332 * deps: send@0.18.033 - Fix emitted 416 error missing headers property34 - Limit the headers removed for 304 response3536 unmodified linesmodified:package.json+1 added-1 removed
43 unmodified lines4445464748484950515247 unmodified lines43 unmodified lines "fresh": "0.5.2", "http-errors": "2.0.0", "merge-descriptors": "1.0.1", "methods": "~1.1.2", "on-finished": "~2.3.0", "on-finished": "2.4.1", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "proxy-addr": "~2.0.7", "qs": "6.10.3",47 unmodified lines