Skip automatic header detection when "keepImplicitHeaders" is active, to prevent duplicate headers.

This commit is contained in:
Tim
2021-09-07 13:14:14 +02:00
parent 3420f02049
commit e4e30d755c
2 changed files with 6 additions and 3 deletions

View File

@@ -2356,7 +2356,10 @@ module.exports = {
} }
pmBody = this.convertToPmBody(reqBody, REQUEST_TYPE.ROOT, components, options, schemaCache); pmBody = this.convertToPmBody(reqBody, REQUEST_TYPE.ROOT, components, options, schemaCache);
item.request.body = pmBody.body; item.request.body = pmBody.body;
if (!options.keepImplicitHeaders || (reqParams.header && reqParams.header.length === 0)) { if (!options.keepImplicitHeaders || (!_.find(reqParams.header, (h) => {
return _.toLower(_.get(h, 'name')) === 'content-type';
}))) {
// Add detected content-type header
item.request.addHeader(pmBody.contentHeader); item.request.addHeader(pmBody.contentHeader);
} }
// extra form headers if encoding is present in request Body. // extra form headers if encoding is present in request Body.

View File

@@ -317,7 +317,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
.to.equal('Content-Type'); .to.equal('Content-Type');
expect(conversionResult.output[0].data.item[0].item[1].request.header[1].value) expect(conversionResult.output[0].data.item[0].item[1].request.header[1].value)
.to.equal('application/json'); .to.equal('application/json');
expect(conversionResult.output[0].data.item[0].item[1].request.header[2]).to.equal(undefined); expect(conversionResult.output[0].data.item[0].item[1].request.header).to.have.length(2);
done(); done();
}); });
}); });
@@ -329,7 +329,7 @@ describe('CONVERT FUNCTION TESTS ', function() {
keepImplicitHeaders: false keepImplicitHeaders: false
}, (err, conversionResult) => { }, (err, conversionResult) => {
expect(err).to.be.null; expect(err).to.be.null;
expect(conversionResult.output[0].data.item[0].item[0].request.header).to.equal(undefined); expect(conversionResult.output[0].data.item[0].item[1].request.header).to.have.length(1);
expect(conversionResult.output[0].data.item[0].item[1].request.header[0].key) expect(conversionResult.output[0].data.item[0].item[1].request.header[0].key)
.to.equal('Content-Type'); .to.equal('Content-Type');
expect(conversionResult.output[0].data.item[0].item[1].request.header[0].value) expect(conversionResult.output[0].data.item[0].item[1].request.header[0].value)