Skip to content

Commit b8b091d

Browse files
Added logic for handling custom cookie in constructor config headers (#75)
* Added logic for handling custom cookie in constructor config headers * Increased version
1 parent 812a4a6 commit b8b091d

5 files changed

Lines changed: 21 additions & 12 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ octane.json
4848
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
4949

5050
# User-specific stuff
51+
.idea/*.xml
5152
.idea/**/workspace.xml
5253
.idea/**/tasks.xml
5354
.idea/**/usage.statistics.xml

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ $ npm test test/query.js
420420
```
421421

422422
## What's new :newspaper: <a name="whats-new"></a>
423+
* 24.2.1
424+
* Added support for providing custom cookie header
425+
423426
* 24.2.0
424427
* HTTP Proxy support
425428
* Added ability to use proxy with credentials

lib/root/requestHandler.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class RequestHandler {
105105

106106
if (params.headers) {
107107
this._options.headers = new AxiosHeaders(params.headers);
108+
109+
const customCookies = this._options.headers['Cookie'];
110+
if (customCookies) {
111+
this._cookieJar.setCookieSync(customCookies, this._options.baseURL);
112+
}
108113
}
109114

110115
this._requestor = axios.create(this._options);
@@ -130,13 +135,13 @@ class RequestHandler {
130135
*/
131136
async get(url: string, config?: AxiosRequestConfig) {
132137
return await this.sendRequestWithCookies(url, async (headersWithCookie) =>
133-
this._requestor.get(url, { ...config, headers: headersWithCookie }))
138+
this._requestor.get(url, { ...config, headers: headersWithCookie }), config?.headers)
134139
.catch(async (err) => {
135140
await this._reauthenticate(err);
136141
return await this.sendRequestWithCookies(url, (headersWithCookie => this._requestor.get(url, {
137142
...config,
138143
headers: headersWithCookie
139-
})));
144+
})), config?.headers);
140145
});
141146
}
142147

@@ -150,13 +155,13 @@ class RequestHandler {
150155
*/
151156
async delete(url: string, config?: AxiosRequestConfig) {
152157
return await this.sendRequestWithCookies(url, async (headersWithCookie) =>
153-
this._requestor.delete(url, { ...config, headers: headersWithCookie }))
158+
this._requestor.delete(url, { ...config, headers: headersWithCookie }), config?.headers)
154159
.catch(async (err) => {
155160
await this._reauthenticate(err);
156161
return this.sendRequestWithCookies(url, (headersWithCookie => this._requestor.delete(url, {
157162
...config,
158163
headers: headersWithCookie
159-
})));
164+
})), config?.headers);
160165
});
161166
}
162167

@@ -171,13 +176,13 @@ class RequestHandler {
171176
*/
172177
async update(url: string, body?: object | string, config?: AxiosRequestConfig) {
173178
return await this.sendRequestWithCookies(url, async (headersWithCookie) =>
174-
this._requestor.put(url, body, { ...config, headers: headersWithCookie }))
179+
this._requestor.put(url, body, { ...config, headers: headersWithCookie }), config?.headers)
175180
.catch(async (err) => {
176181
await this._reauthenticate(err);
177182
return this.sendRequestWithCookies(url, (headersWithCookie => this._requestor.put(url, body, {
178183
...config,
179184
headers: headersWithCookie
180-
})));
185+
})), config?.headers);
181186
});
182187
}
183188

@@ -192,13 +197,13 @@ class RequestHandler {
192197
*/
193198
async create(url: string, body?: object | string, config?: AxiosRequestConfig) {
194199
return await this.sendRequestWithCookies(url, async (headersWithCookie) =>
195-
this._requestor.post(url, body, { ...config, headers: headersWithCookie }))
200+
this._requestor.post(url, body, { ...config, headers: headersWithCookie }), config?.headers)
196201
.catch(async (err) => {
197202
await this._reauthenticate(err);
198203
return this.sendRequestWithCookies(url, (headersWithCookie => this._requestor.post(url, body, {
199204
...config,
200205
headers: headersWithCookie
201-
})));
206+
})), config?.headers);
202207
});
203208

204209
}
@@ -278,7 +283,7 @@ class RequestHandler {
278283
headers: { 'content-type': 'application/octet-stream' },
279284
};
280285

281-
const configHeaders = config === undefined ? undefined : config.headers;
286+
const configHeaders = config?.headers;
282287
const requestHeaders = { ...configHeaders, ...attachmentConfig.headers };
283288

284289
return await this.sendRequestWithCookies(url, async (headersWithCookie) =>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@microfocus/alm-octane-js-rest-sdk",
3-
"version": "24.2.0",
3+
"version": "24.2.1",
44
"description": "NodeJS wrapper for the Open Text ALM Octane API",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)