From 8ac8dce2fe89f8d1289b52d6753ef2867a77ef6a Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Wed, 25 Jun 2025 10:04:30 +0200 Subject: [PATCH 1/3] refactor: avoid external contentType processing for OPC UA so far just for readResource --- packages/binding-opcua/src/codec.ts | 2 +- packages/binding-opcua/src/opcua-protocol-client.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/binding-opcua/src/codec.ts b/packages/binding-opcua/src/codec.ts index 77add05b2..51320ee9b 100644 --- a/packages/binding-opcua/src/codec.ts +++ b/packages/binding-opcua/src/codec.ts @@ -258,7 +258,7 @@ export const theOpcuaJSONCodec = new OpcuaJSONCodec(); export class OpcuaBinaryCodec implements ContentCodec { getMediaType(): string { - return "application/opcua+octet-stream"; // see Ege + return "application/opcua+octet-stream"; } bytesToValue(bytes: Buffer, schema: DataSchema, parameters?: { [key: string]: string }): DataValueJSON { diff --git a/packages/binding-opcua/src/opcua-protocol-client.ts b/packages/binding-opcua/src/opcua-protocol-client.ts index 37b94e5ee..b24cd5dd3 100644 --- a/packages/binding-opcua/src/opcua-protocol-client.ts +++ b/packages/binding-opcua/src/opcua-protocol-client.ts @@ -305,6 +305,9 @@ export class OPCUAProtocolClient implements ProtocolClient { public async readResource(form: OPCUAForm): Promise { debug(`readResource: reading ${form}`); + // node-opcua handles the contentType internally and no further external processing should be done + form.contentType = undefined; + const content = await this._withSession(form, async (session) => { const nodeId = await this._resolveNodeId(form); const dataValue = await session.read({ From fde2f4c1cb884ec3355547c6826039a9641aa8bd Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Wed, 25 Jun 2025 10:11:32 +0200 Subject: [PATCH 2/3] refactor: move removing contentType just before returning --- packages/binding-opcua/src/opcua-protocol-client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/binding-opcua/src/opcua-protocol-client.ts b/packages/binding-opcua/src/opcua-protocol-client.ts index b24cd5dd3..375126523 100644 --- a/packages/binding-opcua/src/opcua-protocol-client.ts +++ b/packages/binding-opcua/src/opcua-protocol-client.ts @@ -302,12 +302,14 @@ export class OPCUAProtocolClient implements ProtocolClient { return this._resolveNodeId2(form, fNodeId as NodeIdLike | NodeByBrowsePath); } + // node-opcua handles the contentType internally and no further *external* processing should be done + private vanishContentType(form: OPCUAForm) { + form.contentType = undefined; + } + public async readResource(form: OPCUAForm): Promise { debug(`readResource: reading ${form}`); - // node-opcua handles the contentType internally and no further external processing should be done - form.contentType = undefined; - const content = await this._withSession(form, async (session) => { const nodeId = await this._resolveNodeId(form); const dataValue = await session.read({ @@ -317,6 +319,7 @@ export class OPCUAProtocolClient implements ProtocolClient { return this._dataValueToContent(form, dataValue); }); debug(`readResource: contentType ${content.type}`); + this.vanishContentType(form); return content; } From b365da456c1e06debd66d941ef058c4a3e88cbe2 Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Wed, 25 Jun 2025 10:33:24 +0200 Subject: [PATCH 3/3] refactor: remove contentType only if not handled by internal OPC UA Codecs --- packages/binding-opcua/src/opcua-protocol-client.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/binding-opcua/src/opcua-protocol-client.ts b/packages/binding-opcua/src/opcua-protocol-client.ts index 375126523..07e8ef1c1 100644 --- a/packages/binding-opcua/src/opcua-protocol-client.ts +++ b/packages/binding-opcua/src/opcua-protocol-client.ts @@ -304,7 +304,9 @@ export class OPCUAProtocolClient implements ProtocolClient { // node-opcua handles the contentType internally and no further *external* processing should be done private vanishContentType(form: OPCUAForm) { - form.contentType = undefined; + if (!(form.contentType === "application/opcua+json" || form.contentType === "application/opcua+octet-stream")) { + form.contentType = undefined; + } } public async readResource(form: OPCUAForm): Promise {