Skip to content

Commit b89cf93

Browse files
committed
Revert "feat!(augmented_form): expose resolvedHref as href"
This reverts commit 737bc39.
1 parent 2e4e5c1 commit b89cf93

File tree

9 files changed

+70
-53
lines changed

9 files changed

+70
-53
lines changed

lib/src/binding_coap/coap_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ final class CoapClient extends ProtocolClient
132132
final code = requestMethod.code;
133133

134134
return _sendRequest(
135-
form.href,
135+
form.resolvedHref,
136136
code,
137137
content: content,
138138
format: form.contentFormat,
@@ -232,7 +232,7 @@ final class CoapClient extends ProtocolClient
232232
) async {
233233
final requestMethod = (form.method ?? CoapRequestMethod.get).code;
234234

235-
final creationHintUri = form.href.replace(scheme: "coap");
235+
final creationHintUri = form.resolvedHref.replace(scheme: "coap");
236236

237237
final request = await _createRequest(
238238
requestMethod,
@@ -419,13 +419,13 @@ final class CoapClient extends ProtocolClient
419419

420420
final request = await _createRequest(
421421
(form.method ?? CoapRequestMethod.get).code,
422-
form.href,
422+
form.resolvedHref,
423423
format: form.contentFormat,
424424
accept: form.accept,
425425
);
426426

427427
final coapClient = coap.CoapClient(
428-
form.href,
428+
form.resolvedHref,
429429
config: _InternalCoapConfig(_coapConfig ?? const CoapConfig()),
430430
);
431431

lib/src/binding_http/http_client.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ final class HttpClient extends ProtocolClient
104104
return false;
105105
}
106106

107-
final basicCredentials = await _getBasicCredentials(form.href, form);
107+
final basicCredentials =
108+
await _getBasicCredentials(form.resolvedHref, form);
108109

109110
if (basicCredentials == null) {
110111
return false;
@@ -126,7 +127,8 @@ final class HttpClient extends ProtocolClient
126127
return false;
127128
}
128129

129-
final bearerCredentials = await _getBearerCredentials(form.href, form);
130+
final bearerCredentials =
131+
await _getBearerCredentials(form.resolvedHref, form);
130132

131133
if (bearerCredentials == null) {
132134
return false;
@@ -220,7 +222,7 @@ final class HttpClient extends ProtocolClient
220222
) async {
221223
final requestMethod =
222224
HttpRequestMethod.getRequestMethod(form, operationType);
223-
final Uri uri = form.href;
225+
final Uri uri = form.resolvedHref;
224226

225227
final request = Request(requestMethod.methodName, uri)
226228
..headers.addAll(_getHeadersFromForm(form))

lib/src/binding_http/http_subscription.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class HttpSseSubscription extends ProtocolSubscription {
2020
void Function(Exception error)? onError,
2121
void Function()? complete,
2222
}) : _active = true,
23-
_sseChannel = SseChannel.connect(form.href) {
23+
_sseChannel = SseChannel.connect(form.resolvedHref) {
2424
_sseChannel.stream.listen(
2525
(data) {
2626
if (data is! String) {

lib/src/binding_mqtt/mqtt_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ final class MqttClient extends ProtocolClient with MqttDiscoverer {
6868
}
6969

7070
Future<MqttServerClient> _connectWithForm(AugmentedForm form) async =>
71-
_connect(form.href, form);
71+
_connect(form.resolvedHref, form);
7272

7373
Future<MqttServerClient> _connect(Uri brokerUri, AugmentedForm? form) async {
7474
final client = brokerUri.createClient(_mqttConfig.keepAlivePeriod);

lib/src/binding_mqtt/mqtt_extensions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ extension MqttFormExtension on AugmentedForm {
140140
if (qosValue != null) {
141141
throw FormatException(
142142
"Encountered unknown QoS value $qosValue. "
143-
"in form with resolved href $href.",
143+
"in form with resolved href $resolvedHref.",
144144
);
145145
}
146146

lib/src/core/implementation/augmented_form.dart

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ final class AugmentedForm implements Form {
4444
@override
4545
String get contentType => _form.contentType;
4646

47-
/// Resolves all [_userProvidedUriVariables] in this [Form] and returns the
48-
/// resulting [Uri].
49-
Uri get _resolvedHref {
47+
@override
48+
Uri get href {
5049
final baseUri = _thingDescription.base;
5150

5251
if (baseUri != null) {
@@ -56,39 +55,6 @@ final class AugmentedForm implements Form {
5655
return _form.href;
5756
}
5857

59-
@override
60-
Uri get href {
61-
final href = _resolvedHref;
62-
final hrefUriVariables = _filterUriVariables(href);
63-
64-
if (hrefUriVariables.isEmpty) {
65-
return href;
66-
}
67-
68-
final Map<String, DataSchema> affordanceUriVariables = {
69-
..._thingDescription.uriVariables ?? {},
70-
..._interactionAffordance.uriVariables ?? {},
71-
};
72-
73-
final userProvidedUriVariables = _userProvidedUriVariables;
74-
75-
if (userProvidedUriVariables != null) {
76-
_validateUriVariables(
77-
hrefUriVariables,
78-
affordanceUriVariables,
79-
userProvidedUriVariables,
80-
);
81-
}
82-
83-
// As "{" and "}" are "percent encoded" due to Uri.parse(), we need to
84-
// revert the encoding first before we can insert the values.
85-
final decodedHref = Uri.decodeFull(href.toString());
86-
87-
final expandedHref =
88-
UriTemplate(decodedHref).expand(userProvidedUriVariables ?? {});
89-
return Uri.parse(expandedHref);
90-
}
91-
9258
@override
9359
List<OperationType> get op =>
9460
_form.op ?? OperationType.defaultOpValues(_interactionAffordance);
@@ -129,6 +95,38 @@ final class AugmentedForm implements Form {
12995
.toList(growable: false);
13096
}
13197

98+
/// Resolves all [_userProvidedUriVariables] in this [Form] and returns the
99+
/// resulting [Uri].
100+
Uri get resolvedHref {
101+
final hrefUriVariables = _filterUriVariables(href);
102+
103+
if (hrefUriVariables.isEmpty) {
104+
return href;
105+
}
106+
107+
final Map<String, DataSchema> affordanceUriVariables = {
108+
..._thingDescription.uriVariables ?? {},
109+
..._interactionAffordance.uriVariables ?? {},
110+
};
111+
112+
final userProvidedUriVariables = _userProvidedUriVariables;
113+
if (userProvidedUriVariables != null) {
114+
_validateUriVariables(
115+
hrefUriVariables,
116+
affordanceUriVariables,
117+
userProvidedUriVariables,
118+
);
119+
}
120+
121+
// As "{" and "}" are "percent encoded" due to Uri.parse(), we need to
122+
// revert the encoding first before we can insert the values.
123+
final decodedHref = Uri.decodeFull(href.toString());
124+
125+
final expandedHref =
126+
UriTemplate(decodedHref).expand(userProvidedUriVariables ?? {});
127+
return Uri.parse(expandedHref);
128+
}
129+
132130
void _validateUriVariables(
133131
List<String> uriVariablesInHref,
134132
Map<String, DataSchema> affordanceUriVariables,

lib/src/core/implementation/consumed_thing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ConsumedThing implements scripting_api.ConsumedThing {
7878
}
7979

8080
return servient.supportsOperation(
81-
form.href.scheme,
81+
form.resolvedHref.scheme,
8282
operationType,
8383
form.subprotocol,
8484
);

test/core/augmented_form_test.dart

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ void main() {
144144
);
145145

146146
expect(
147-
augmentedForm1.href,
147+
augmentedForm1.resolvedHref,
148148
Uri.parse("http://example.org/weather/?lat=5&long=10"),
149149
);
150150

151+
expect(
152+
augmentedForm1.resolvedHref != augmentedForm1.href,
153+
isTrue,
154+
);
155+
151156
final augmentedForm2 = AugmentedForm(
152157
affordance.forms.first,
153158
affordance,
@@ -158,7 +163,7 @@ void main() {
158163
);
159164

160165
expect(
161-
augmentedForm2.href,
166+
augmentedForm2.resolvedHref,
162167
Uri.parse("http://example.org/weather/?lat=5"),
163168
);
164169

@@ -172,7 +177,7 @@ void main() {
172177
);
173178

174179
expect(
175-
augmentedForm3.href,
180+
augmentedForm3.resolvedHref,
176181
Uri.parse("http://example.org/weather/?long=10"),
177182
);
178183

@@ -187,7 +192,7 @@ void main() {
187192
);
188193

189194
expect(
190-
() => augmentedForm4.href,
195+
() => augmentedForm4.resolvedHref,
191196
throwsA(isA<FormatException>()),
192197
);
193198

@@ -202,9 +207,21 @@ void main() {
202207
);
203208

204209
expect(
205-
() => augmentedForm5.href,
210+
() => augmentedForm5.resolvedHref,
206211
throwsA(isA<FormatException>()),
207212
);
213+
214+
final augmentedForm6 = AugmentedForm(
215+
affordance.forms[2],
216+
affordance,
217+
thingDescription,
218+
const {},
219+
);
220+
221+
expect(
222+
augmentedForm6.href,
223+
augmentedForm6.resolvedHref,
224+
);
208225
});
209226
});
210227
}

test/core/discovery_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ final class _MockedProtocolClient extends ProtocolClient with DirectDiscoverer {
147147

148148
@override
149149
Future<Content> readResource(AugmentedForm form) async {
150-
final href = form.href;
150+
final href = form.resolvedHref;
151151

152152
if (href == directoryTestThingsUri1) {
153153
return "[$validTestThingDescription]".toContent("application/td+json");

0 commit comments

Comments
 (0)