From 1e840a11e5fa64cadd7728935a13c56cd25f3a5e Mon Sep 17 00:00:00 2001 From: Wilsimar Fabricio da Silva Date: Tue, 22 Sep 2020 19:22:57 -0300 Subject: [PATCH 1/2] Implementation to enable receiving headers when establishing connection. Exemplo: headers:{ 'User-Agent': 'MyUserAgent'}. --- src/jira.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/jira.js b/src/jira.js index bc395df0..dbcfcd42 100644 --- a/src/jira.js +++ b/src/jira.js @@ -27,6 +27,10 @@ export default class JiraApi { this.greenhopperVersion = options.greenhopperVersion || '1.0'; this.baseOptions = {}; + if (options.headers){ + this.headers = options.headers; + } + if (options.ca) { this.baseOptions.ca = options.ca; } @@ -122,13 +126,19 @@ export default class JiraApi { * @param {object} [options] - an object containing fields and formatting how the */ makeRequestHeader(uri, options = {}) { - return { + var optionsRequestHeader = { rejectUnauthorized: this.strictSSL, method: options.method || 'GET', uri, json: true, ...options, }; + + if (this.headers){ + optionsRequestHeader.headers = this.headers; + }; + + return optionsRequestHeader; } /** From 568f377a9a9dc390263ffe76e8726261ac6e0a9d Mon Sep 17 00:00:00 2001 From: Wilsimar Fabricio da Silva Date: Fri, 29 Jan 2021 16:36:39 -0300 Subject: [PATCH 2/2] tests whith headers --- test/jira-tests.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/jira-tests.js b/test/jira-tests.js index 676a44ac..6fbd8378 100644 --- a/test/jira-tests.js +++ b/test/jira-tests.js @@ -16,6 +16,7 @@ function getOptions(options) { intermediatePath: actualOptions.intermediatePath, bearer: actualOptions.bearer || null, ca: actualOptions.ca || null, + headers: actualOptions.headers || null, }; } @@ -1037,5 +1038,24 @@ describe('Jira API Tests', () => { const result = await dummyURLCall('genericGet', ['field']); result.should.eql('http://jira.somehost.com:8080/rest/api/2.0/field'); }); + + it('Constructor with headers options', () => { + const options = getOptions({ + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + 'User-Agent': 'someUserAgent', + }, + }); + + const jira = new JiraApi(options); + + expect(jira.headers).to.eql({ + Accept: 'application/json', + 'Content-Type': 'application/json', + 'User-Agent': 'someUserAgent', + }); + }); + }); });