Permalink
Browse files

finish event fired on req before end event

  • Loading branch information...
1 parent f128e3f commit fe481393dfec13e7febd2dce793b928e88bb144e @ahildoer ahildoer committed Jan 23, 2014
Showing with 31 additions and 1 deletion.
  1. +1 −0 lib/request_overrider.js
  2. +30 −1 tests/test_intercept.js
View
@@ -105,6 +105,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
if (!aborted && !ended) {
req.write(buffer, encoding);
end(cb);
+ req.emit('finish');
req.emit('end');
}
};
View
@@ -2222,6 +2222,35 @@ test('delay works with when you return a generic stream from the reply callback'
}).end('OK');
});
+test("finish event fired before end event (bug-139)", function(t) {
+ var scope = nock('http://www.filterboddiezregexp.com')
+ .filteringRequestBody(/mia/, 'nostra')
+ .post('/', 'mamma nostra')
+ .reply(200, "Hello World!");
+
+ var finishCalled = false;
+ var req = http.request({
+ host: "www.filterboddiezregexp.com"
+ , method: 'POST'
+ , path: '/'
+ , port: 80
+ }, function(res) {
+ t.equal(finishCalled, true);
+ t.equal(res.statusCode, 200);
+ res.on('end', function() {
+ scope.done();
+ t.end();
+ });
+ });
+
+ req.on('finish', function() {
+ finishCalled = true;
+ });
+
+ req.end('mamma mia');
+
+});
+
if (stream.Readable) {
test('when a stream is used for the response body, it will not be read until after the response event', function (t) {
var responseEvent = false;
@@ -2259,4 +2288,4 @@ if (stream.Readable) {
});
});
});
-}
+}

0 comments on commit fe48139

Please sign in to comment.