[fix] Wait for `process.nextTick` if the Request has not drained yet #75

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+18 −16
Split
View
@@ -109,24 +109,26 @@ Router.prototype.dispatch = function (req, res, callback) {
}
if (!stream) {
- //
- // If there is no streaming required on any of the functions on the
- // way to `path`, then attempt to parse the fully buffered request stream
- // once it has emitted the `end` event.
- //
- if (req.readable) {
+ process.nextTick(function () {
//
- // If the `http.ServerRequest` is still readable, then await
- // the end event and then continue
+ // If there is no streaming required on any of the functions on the
+ // way to `path`, then attempt to parse the fully buffered request stream
+ // once it has emitted the `end` event.
//
- req.once('end', parseAndInvoke)
- }
- else {
- //
- // Otherwise, just parse the body now.
- //
- parseAndInvoke();
- }
+ if (req.readable) {
+ //
+ // If the `http.ServerRequest` is still readable, then await
+ // the end event and then continue
+ //
+ req.once('end', parseAndInvoke)
+ }
+ else {
+ //
+ // Otherwise, just parse the body now.
+ //
+ parseAndInvoke();
+ }
+ });
}
else {
this.invoke(runlist, thisArg, callback);