From 024ab4a2d5576ae44e596ef0e355dca68a088801 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sun, 10 Dec 2023 19:11:36 +0100 Subject: [PATCH] fixup! feat: implement requestThingDescription method --- lib/src/binding_coap/coap_client.dart | 6 ++---- lib/src/binding_http/http_client.dart | 14 +++++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/src/binding_coap/coap_client.dart b/lib/src/binding_coap/coap_client.dart index 0bf5a828..b9b7d818 100644 --- a/lib/src/binding_coap/coap_client.dart +++ b/lib/src/binding_coap/coap_client.dart @@ -531,12 +531,10 @@ final class CoapClient implements ProtocolClient { } @override - Future requestThingDescription(Uri url) async => - // TODO(JKRhb): Implement a different method here. - _sendDiscoveryRequest( + Future requestThingDescription(Uri url) async => _sendRequest( url, coap.RequestMethod.get, form: null, - format: coap.CoapMediaType.applicationTdJson, + accept: coap.CoapMediaType.applicationTdJson, ); } diff --git a/lib/src/binding_http/http_client.dart b/lib/src/binding_http/http_client.dart index c3909ff6..b2b3aeeb 100644 --- a/lib/src/binding_http/http_client.dart +++ b/lib/src/binding_http/http_client.dart @@ -328,8 +328,16 @@ final class HttpClient implements ProtocolClient { } @override - Future requestThingDescription(Uri url) { - // TODO: implement requestThingDescription - throw UnimplementedError(); + Future requestThingDescription(Uri url) async { + final request = Request(HttpRequestMethod.get.methodName, url); + const tdContentType = 'application/td+json'; + request.headers['Accept'] = tdContentType; + + final response = await _client.send(request); + + return Content( + response.headers['Content-Type'] ?? tdContentType, + response.stream, + ); } }