Skip to content

Commit

Permalink
workaround for socket hang up
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kuba committed Jun 5, 2017
1 parent f984668 commit 5db4fa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 7 additions & 9 deletions lib/recorder.js
Expand Up @@ -337,22 +337,20 @@ function record(rec_options) {
}
bodyChunks.push(data);
}
oldWrite.call(req, data);
oldWrite.apply(req, arguments);
}
};

// in Node 8, res.end() does not call res.write() directly
if (semver.satisfies(process.version, '>=8')) {
var oldEnd = req.end;
req.end = function(data, encoding, callback) {
if ('undefined' !== typeof(data)) {
if (data) {
debug(thisRecordingId, 'new', proto, 'body chunk');
if (! Buffer.isBuffer(data)) {
data = new Buffer(data, encoding);
}
bodyChunks.push(data);
req.end = function(data, encoding) {
if (data) {
debug(thisRecordingId, 'new', proto, 'body chunk');
if (! Buffer.isBuffer(data)) {
data = new Buffer(data, encoding);
}
bodyChunks.push(data);
}
oldEnd.apply(req, arguments);
};
Expand Down
6 changes: 2 additions & 4 deletions tests/test_recorder.js
Expand Up @@ -280,8 +280,7 @@ test('records nonstandard ports', function(t) {

// Create test http server and perform the tests while it's up.
var testServer = http.createServer(function(req, res) {
res.write(RESPONSE_BODY);
res.end();
res.end(RESPONSE_BODY);
}).listen(8081, function(err) {

t.equal(err, undefined);
Expand Down Expand Up @@ -731,8 +730,7 @@ test('works with clients listening for readable', {skip: process.env.AIRPLANE},

// Create test http server and perform the tests while it's up.
var testServer = http.createServer(function(req, res) {
res.write(RESPONSE_BODY);
res.end();
res.end(RESPONSE_BODY);
}).listen(8081, function(err) {

// t.equal(err, undefined);
Expand Down

0 comments on commit 5db4fa0

Please sign in to comment.