diff --git a/lib/interceptor.js b/lib/interceptor.js index c999e74df..f058ace6f 100755 --- a/lib/interceptor.js +++ b/lib/interceptor.js @@ -73,6 +73,7 @@ Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) { if (this.scope._defaultReplyHeaders) { headers = headers || {}; + headers = common.headersFieldNamesToLowerCase(headers); headers = mixin(this.scope._defaultReplyHeaders, headers); } diff --git a/tests/test_intercept.js b/tests/test_intercept.js index 0feb9bd46..a53048de6 100755 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -196,6 +196,41 @@ test("reply should throw on error on the callback", function(t) { req.end(); }); +test("reply should not cause an error on header conflict", function(t) { + var dataCalled = false; + + var scope = nock('http://www.google.com') + .defaultReplyHeaders({ + 'content-type': 'application/json' + }); + + scope + .get('/') + .reply(200, '', { + 'Content-Type': 'application/xml' + }); + + var req = http.request({ + host: "www.google.com", + path: '/', + port: 80 + }, function(res) { + t.equal(res.statusCode, 200); + res.on('end', function() { + t.ok(dataCalled); + scope.done(); + t.end(); + }); + res.on('data', function(data) { + dataCalled = true; + t.equal(res.headers['content-type'], "application/xml"); + t.equal(data.toString(), "", "response should match"); + }); + }); + + req.end(); +}); + test("get gets mocked", function(t) { var dataCalled = false;