diff --git a/docs/connectionParameters.html b/docs/connectionParameters.html
index 9fd001f3..b50b689c 100644
--- a/docs/connectionParameters.html
+++ b/docs/connectionParameters.html
@@ -114,6 +114,11 @@
string |
An optional value to override the instance key which is used for the caches of schemas, options, etc. |
+
+ | enableRequestIdHeader |
+ boolean |
+ Enable the request ID header for SOAP API calls |
+
diff --git a/src/client.js b/src/client.js
index c0b363f0..e17eba68 100644
--- a/src/client.js
+++ b/src/client.js
@@ -309,6 +309,7 @@ class Credentials {
* @property {number} timeout - Can be set to change the HTTP call timeout. Value is passed in ms.
* @property {string} cacheRootKey - "default" or "none" - determine the prefix to use for the keys in the caches of schemas, options, etc.
* @property {string} instanceKey - an optional value to override the instance key which is used for the caches of schemas, options, etc.
+ * @property {boolean} enableRequestIdHeader - an optional value to enable the request ID header for SOAP API calls
* @memberOf Campaign
*/
@@ -1185,10 +1186,12 @@ class Client {
} catch (error) {
console.error("Failed to generate request ID", error);
}
- const updatedExtraHttpHeaders = requestId ? Object.assign({}, extraHttpHeaders, {
- "x-request-id": requestId,
- })
- : extraHttpHeaders;
+ const enableRequestIdHeader = this._connectionParameters._options?.enableRequestIdHeader;
+ const updatedExtraHttpHeaders = (enableRequestIdHeader && requestId)
+ ? Object.assign({}, extraHttpHeaders, {
+ "x-request-id": requestId,
+ })
+ : extraHttpHeaders;
const soapCall = new SoapMethodCall(this._transport, urn, method,
this._sessionToken, this._securityToken,
this._getUserAgentString(),
diff --git a/test/client.test.js b/test/client.test.js
index 57c745fc..181f3d37 100644
--- a/test/client.test.js
+++ b/test/client.test.js
@@ -3447,8 +3447,8 @@ describe('ACC Client', function () {
});
});
- it("Should add x-request-id header to every SOAP call", async () => {
- const client = await Mock.makeClient();
+ it("Should add x-request-id header to SOAP call when enableRequestIdHeader is true", async () => {
+ const client = await Mock.makeClient({ enableRequestIdHeader: true });
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
await client.NLWS.xtkSession.logon();
@@ -3480,7 +3480,37 @@ describe('ACC Client', function () {
});
it("Should call SOAP call on request ID generation failure", async () => {
- const client = await Mock.makeClient();
+ const client = await Mock.makeClient({enableRequestIdHeader: true});
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
+ await client.NLWS.xtkSession.logon();
+
+ const mockGetUUID = jest.spyOn(Util, 'getUUID').mockImplementation(() => { throw new Error('UUID error'); });
+
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
+ const queryDef = {
+ "schema": "nms:extAccount",
+ "operation": "select",
+ "select": {
+ "node": [{ "expr": "@id" }]
+ }
+ };
+
+ const query = client.NLWS.xtkQueryDef.create(queryDef);
+
+ const headers = await collectHeaders(client, async() => {
+ await query.executeQuery();
+ });
+
+ expect(headers["x-request-id"]).toBeUndefined();
+
+ // Restore the mock
+ mockGetUUID.mockRestore();
+ });
+
+
+ it("Should not add x-request-id header to SOAP call when enableRequestIdHeader is false", async () => {
+ const client = await Mock.makeClient({ enableRequestIdHeader: false });
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
await client.NLWS.xtkSession.logon();