From f24d9e70d156aef9ebf86921ca1519f2a3165b28 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Tue, 19 Sep 2023 08:26:33 +0200 Subject: [PATCH] fixup! feat!: add proposal for new discovery API --- packages/binding-coap/src/coap-client.ts | 7 ++----- packages/binding-http/src/http-client-impl.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) 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); } }