Skip to content
Myr

Fix res.sendFile not always detecting aborted connection

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #2489

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 935f05b · Browse files · 2 files+19 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−13 removed

  • other:+19 added−13 removed

2 files+19 added−13 removed

modified:lib/response.js+18 added-13 removed
905 unmodified lines
906907// pipe the send file stream908function sendfile(res, file, options, callback) {909 var done = false;910 var streaming = false;910 var streaming;911912 // request aborted913 function onaborted() {914 if (done) return;915 done = true;916917 var err = new Error('Request aborted');918 err.code = 'ECONNABORT';919 callback(err);920 }921922 // directory923 function ondirectory() {924 if (done) return;925 done = true;
4 unmodified lines
930 }931932 // errors933 function onerror(err) {924 if (!err) return;934 if (done) return;935 done = true;936 callback(err);937 }
6 unmodified lines
944 }945946 // file947 function onfile() {939 onFinished(res, onfinish);948 streaming = false;949 }950951 // finished952 function onfinish(err) {953 if (err) return onerror(err);954 if (done) return;955956 setImmediate(function () {948 if (done) return;949 done = true;950951 if (!streaming) {952 callback();957 if (streaming !== false && !done) {958 onaborted();959 return;960 }961956 // response finished before end of file957 var err = new Error('Request aborted');958 err.code = 'ECONNABORT';959 callback(err);962 if (done) return;963 done = true;964 callback();965 });966 }967968 // streaming
5 unmodified lines
974 file.on('end', onend);975 file.on('error', onerror);976 file.on('file', onfile);977 file.on('stream', onstream);973 onFinished(res, onerror);978 onFinished(res, onfinish);979980 if (options.headers) {981 // set headers on successful transfer982 file.on('headers', function headers(res) {
13 unmodified lines
modified:History.md+1 added
1 unmodified line
2==========34 * Deprecate leading `:` in `name` for `app.param(name, fn)`5 * Fix `OPTIONS` responses to include the `HEAD` method properly6 * Fix `res.sendFile` not always detecting aborted connection784.10.8 / 2015-01-139===================10
2546 unmodified lines