Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept ClientRequest.flushHeaders() #1016

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/request_overrider.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
}
};

req.flushHeaders = function() {
debug('req.flushHeaders');
if (!aborted && !ended) {
end(cb);
}
if (aborted) {
emitError(new Error('Request aborted'));
}
};

req.abort = function() {
if (aborted) {
return;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ tap.test('deleteHeadersField deletes fields with case-insensitive field names',

});

tap.test('matchStringOrRegexp', {only: true}, function (t) {
tap.test('matchStringOrRegexp', function (t) {
t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches');
t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match');

Expand Down
24 changes: 20 additions & 4 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test("allow unmocked works (2)", function(t) {
});
});

test("allow unmocked works after one interceptor is removed", {only: true}, function(t) {
test("allow unmocked works after one interceptor is removed", function(t) {
nock("https://example.org",{allowUnmocked: true}).
get("/").
reply(200, "Mocked");
Expand All @@ -72,9 +72,6 @@ test("allow unmocked works after one interceptor is removed", {only: true}, func

mikealRequest("https://example.org/unmocked", function(err, resp, body) {
t.error(err);
console.log(`\nbody ==============================`)
console.log(body)

t.assert(~body.indexOf('Example Domain'));
t.end();
});
Expand Down Expand Up @@ -5235,6 +5232,25 @@ test('correctly parse request without specified path (#1003)', function(t) {
}).end();
});

test('data is sent with flushHeaders', function(t) {
nock.cleanAll();

var scope1 = nock('https://example.com')
.get('')
.reply(200, 'this is data');

https.request({hostname: 'example.com'}, function(res) {
t.equal(res.statusCode, 200);
res.on('data', function(data) {
t.equal(data.toString(), 'this is data');
});
res.on('end', function() {
scope1.done();
t.end();
});
}).flushHeaders();
});

test("teardown", function(t) {
var leaks = Object.keys(global)
.splice(globalCount, Number.MAX_VALUE);
Expand Down