Skip to content
Myr

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

4 files+205 added−1 removed

modified:test/res.download.js+73 added
1'use strict'23var after = require('after');4var assert = require('assert')5var asyncHooks = tryRequire('async_hooks')6var Buffer = require('safe-buffer').Buffer7var express = require('..');8var path = require('path')9var request = require('supertest');10var utils = require('./support/utils')1112var FIXTURES_PATH = path.join(__dirname, 'fixtures')1314var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'15 ? describe16 : describe.skip1718describe('res', function(){19 describe('.download(path)', function(){20 it('should transfer as an attachment', function(done){21 var app = express();
67 unmodified lines
89 .expect('Content-Type', 'text/html; charset=UTF-8')90 .expect('Content-Disposition', 'attachment; filename="user.html"')91 .expect(200, cb);92 })9394 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' }99100 app.use(function (req, res, next) {101 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()102 req.asyncLocalStorage.run(store, next)103 })104105 app.use(function (req, res) {106 res.download('test/fixtures/name.txt', function (err) {107 if (err) return cb(err)108109 var local = req.asyncLocalStorage.getStore()110111 assert.strictEqual(local.foo, 'bar')112 cb()113 })114 })115116 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 })122123 it('should presist store on error', function (done) {124 var app = express()125 var store = { foo: 'bar' }126127 app.use(function (req, res, next) {128 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()129 req.asyncLocalStorage.run(store, next)130 })131132 app.use(function (req, res) {133 res.download('test/fixtures/does-not-exist', function (err) {134 var local = req.asyncLocalStorage.getStore()135136 if (local) {137 res.setHeader('x-store-foo', String(local.foo))138 }139140 res.send(err ? 'got ' + err.status + ' error' : 'no error')141 })142 })143144 request(app)145 .get('/')146 .expect(200)147 .expect('x-store-foo', 'bar')148 .expect('got 404 error')149 .end(done)150 })151 })152 })153154 describe('.download(path, options)', function () {155 it('should allow options to res.sendFile()', function (done) {
331 unmodified lines
487 .expect(200, 'failed', done)488 })489 })490})491492function 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'23var after = require('after');4var asyncHooks = tryRequire('async_hooks')5var Buffer = require('safe-buffer').Buffer6var express = require('../')7 , request = require('supertest')8 , assert = require('assert');
1 unmodified line
10var path = require('path');11var fixtures = path.join(__dirname, 'fixtures');12var utils = require('./support/utils');1314var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'15 ? describe16 : describe.skip1718describe('res', function(){19 describe('.sendFile(path)', function () {20 it('should error missing path', function (done) {21 var app = createApp();
243 unmodified lines
265 request(app)266 .get('/')267 .expect(200, 'got 404 error', done)268 })269270 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' }275276 app.use(function (req, res, next) {277 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()278 req.asyncLocalStorage.run(store, next)279 })280281 app.use(function (req, res) {282 res.sendFile(path.resolve(fixtures, 'name.txt'), function (err) {283 if (err) return cb(err)284285 var local = req.asyncLocalStorage.getStore()286287 assert.strictEqual(local.foo, 'bar')288 cb()289 })290 })291292 request(app)293 .get('/')294 .expect('Content-Type', 'text/plain; charset=UTF-8')295 .expect(200, 'tobi', cb)296 })297298 it('should presist store on error', function (done) {299 var app = express()300 var store = { foo: 'bar' }301302 app.use(function (req, res, next) {303 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()304 req.asyncLocalStorage.run(store, next)305 })306307 app.use(function (req, res) {308 res.sendFile(path.resolve(fixtures, 'does-not-exist'), function (err) {309 var local = req.asyncLocalStorage.getStore()310311 if (local) {312 res.setHeader('x-store-foo', String(local.foo))313 }314315 res.send(err ? 'got ' + err.status + ' error' : 'no error')316 })317 })318319 request(app)320 .get('/')321 .expect(200)322 .expect('x-store-foo', 'bar')323 .expect('got 404 error')324 .end(done)325 })326 })327 })328329 describe('.sendFile(path, options)', function () {330 it('should pass options to send module', function (done) {
730 unmodified lines
1061 request(app)1062 .get('/')1063 .end(function(){});1064 })10651066 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' }10711072 app.use(function (req, res, next) {1073 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()1074 req.asyncLocalStorage.run(store, next)1075 })10761077 app.use(function (req, res) {1078 res.sendfile('test/fixtures/name.txt', function (err) {1079 if (err) return cb(err)10801081 var local = req.asyncLocalStorage.getStore()10821083 assert.strictEqual(local.foo, 'bar')1084 cb()1085 })1086 })10871088 request(app)1089 .get('/')1090 .expect('Content-Type', 'text/plain; charset=UTF-8')1091 .expect(200, 'tobi', cb)1092 })10931094 it('should presist store on error', function (done) {1095 var app = express()1096 var store = { foo: 'bar' }10971098 app.use(function (req, res, next) {1099 req.asyncLocalStorage = new asyncHooks.AsyncLocalStorage()1100 req.asyncLocalStorage.run(store, next)1101 })11021103 app.use(function (req, res) {1104 res.sendfile('test/fixtures/does-not-exist', function (err) {1105 var local = req.asyncLocalStorage.getStore()11061107 if (local) {1108 res.setHeader('x-store-foo', String(local.foo))1109 }11101111 res.send(err ? 'got ' + err.status + ' error' : 'no error')1112 })1113 })11141115 request(app)1116 .get('/')1117 .expect(200)1118 .expect('x-store-foo', 'bar')1119 .expect('got 404 error')1120 .end(done)1121 })1122 })1123 })11241125 describe('.sendfile(path)', function(){1126 it('should not serve dotfiles', function(done){
273 unmodified lines
1400 });14011402 return app;1403}14041405function tryRequire (name) {1406 try {1407 return require(name)1408 } catch (e) {1409 return {}1410 }1411}
modified:History.md+2 added
24 unmodified lines
25 * 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 response
3536 unmodified lines
modified:package.json+1 added-1 removed