diff --git a/packages/binding-coap/src/coap-client.ts b/packages/binding-coap/src/coap-client.ts index 63a34a04d..12fe7cc74 100644 --- a/packages/binding-coap/src/coap-client.ts +++ b/packages/binding-coap/src/coap-client.ts @@ -62,11 +62,8 @@ export default class CoapClient implements ProtocolClient { req.setOption("Accept", "application/td+json"); return new Promise((resolve, reject) => { req.on("response", (res: IncomingMessage) => { - let contentType = res.headers["Content-Format"]; - if (typeof contentType !== "string") { - contentType = "application/td+json"; - } - resolve({ type: contentType, body: Readable.from(res.payload) }); + const contentType = (res.headers["Content-Format"] as string) ?? "application/td+json"; + resolve(new Content(contentType, Readable.from(res.payload))); }); req.on("error", (err: Error) => reject(err)); req.end(); diff --git a/packages/binding-http/src/http-client-impl.ts b/packages/binding-http/src/http-client-impl.ts index d693cd23c..c13737744 100644 --- a/packages/binding-http/src/http-client-impl.ts +++ b/packages/binding-http/src/http-client-impl.ts @@ -425,6 +425,6 @@ export default class HttpClient implements ProtocolClient { const response = await fetch(uri, { headers }); // TODO: Result should be validated const body = ProtocolHelpers.toNodeStream(response.body as Readable); - return { type: response.headers.get("content-type"), body }; + return new Content(response.headers.get("content-type") ?? "application/td+json", body); } }