Skip to content

Commit

Permalink
fix: case insensitive reply headers (nock#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcstone09 authored and gr2m committed Feb 12, 2018
1 parent 797c518 commit 8fd0942
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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);
}

Expand Down
35 changes: 35 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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, '<html></html>', {
'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(), "<html></html>", "response should match");
});
});

req.end();
});

test("get gets mocked", function(t) {
var dataCalled = false;

Expand Down

0 comments on commit 8fd0942

Please sign in to comment.