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

Resolved Issue #804 #862

Merged
merged 1 commit into from
Feb 12, 2018
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
1 change: 1 addition & 0 deletions lib/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) {

if (this.scope._defaultReplyHeaders) {
headers = headers || {};
headers = common.headersFieldNamesToLowerCase(headers);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iangreenleaf This corrects the throwing conflict exception. Do we have test cases for testing overrides of the default headers when strings are loosely matching ('SomEthing' ==='something')?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moaxaca Not sure off the top of my head

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianwsperber This test could over that.

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 @@ -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, '<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