diff --git a/lib/request_overrider.js b/lib/request_overrider.js index c41509065..b369fae97 100644 --- a/lib/request_overrider.js +++ b/lib/request_overrider.js @@ -54,12 +54,12 @@ function setHeader(request, name, value) { // request headers). function setRequestHeaders(req, options, interceptor) { // We mock request headers if these were specified. - if (interceptor.reqheaders) { - _.forOwn(interceptor.reqheaders, function(val, key) { - if (!_.isFunction(val)) - setHeader(req, key, val); - }); - } + // if (interceptor.reqheaders) { + // _.forOwn(interceptor.reqheaders, function(val, key) { + // if (!_.isFunction(val)) + // setHeader(req, key, val); + // }); + // } // If a filtered scope is being used we have to use scope's host // in the header, otherwise 'host' header won't match. @@ -236,6 +236,7 @@ function RequestOverrider(req, options, interceptors, remove, cb) { /// like to change request.path in mid-flight. options.path = req.path; + // TODO: sets accept header for first request to value of 2nd mock ¯\_(ツ)_/¯ interceptors.forEach(function(interceptor) { // For correct matching we need to have correct request headers - if these were specified. setRequestHeaders(req, options, interceptor); diff --git a/tests/test_intercept.js b/tests/test_intercept.js index 27340b057..3fb8b3209 100644 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -5122,6 +5122,54 @@ test('match multiple paths to domain using regexp with allowUnmocked (#835)', fu }); }); +test('multiple interceptors override headers from unrelated request', function (t) { + nock.cleanAll(); + + nock.define([ + { + scope: 'https://api.github.com:443', + method: 'get', + path: '/bar', + reqheaders: { + 'x-foo': 'bar' + }, + status: 200, + response: {} + }, + { + scope: 'https://api.github.com:443', + method: 'get', + path: '/baz', + reqheaders: { + 'x-foo': 'baz' + }, + status: 200, + response: {} + } + ]) + + mikealRequest({ + url: 'https://api.github.com/bar', + headers: { + 'x-foo': 'bar' + } + }, function (err, res, body) { + t.error(err); + t.equal(res.statusCode, 200); + + mikealRequest.get({ + url: 'https://api.github.com/baz', + headers: { + 'x-foo': 'baz' + } + }, function (err, res, body) { + t.error(err); + t.equal(res.statusCode, 200); + t.end(); + }); + }); +}); + test("teardown", function(t) { var leaks = Object.keys(global) .splice(globalCount, Number.MAX_VALUE);