@@ -13,6 +13,7 @@ import "package:shelf_router/shelf_router.dart";
1313import "../../core.dart" hide ExposedThing;
1414
1515import "http_config.dart" ;
16+ import "http_extensions.dart" ;
1617
1718/// A [ProtocolServer] for the Hypertext Transfer Protocol (HTTP).
1819final class HttpServer implements ProtocolServer {
@@ -104,7 +105,9 @@ final class HttpServer implements ProtocolServer {
104105 // TODO: Handle values from protocol bindings
105106 case Property (: final readOnly, : final writeOnly):
106107 if (! writeOnly) {
107- router.get (path, (request) async {
108+ const operationType = OperationType .readproperty;
109+ final methodName = operationType.defaultHttpMethod;
110+ router.add (methodName, path, (request) async {
108111 final content = await thing.handleReadProperty (affordance.key);
109112
110113 return Response (
@@ -120,14 +123,16 @@ final class HttpServer implements ProtocolServer {
120123 Form (
121124 affordanceUri,
122125 op: const [
123- OperationType .readproperty ,
126+ operationType ,
124127 ],
125128 ),
126129 );
127130 }
128131
129132 if (! readOnly) {
130- router.put (path, (request) async {
133+ const operationType = OperationType .writeproperty;
134+ final methodName = operationType.defaultHttpMethod;
135+ router.add (methodName, path, (request) async {
131136 if (request is ! Request ) {
132137 throw Exception ();
133138 }
@@ -151,14 +156,16 @@ final class HttpServer implements ProtocolServer {
151156 Form (
152157 affordanceUri,
153158 op: const [
154- OperationType .writeproperty ,
159+ operationType ,
155160 ],
156161 ),
157162 );
158163 }
159164 // TODO: Handle observe
160165 case Action ():
161- router.post (path, (request) async {
166+ const operationType = OperationType .invokeaction;
167+ final methodName = operationType.defaultHttpMethod;
168+ router.add (methodName, path, (request) async {
162169 if (request is ! Request ) {
163170 throw Exception ();
164171 }
@@ -167,13 +174,24 @@ final class HttpServer implements ProtocolServer {
167174 request.mimeType ?? "application/json" ,
168175 request.read (),
169176 );
170- await thing.handleWriteProperty (affordance.key, content);
177+ final blah =
178+ await thing.handleInvokeAction (affordance.key, content);
171179
172180 return Response (
181+ body: blah? .body,
173182 204 ,
174183 );
175184 });
176185
186+ affordanceValue.forms.add (
187+ Form (
188+ affordanceUri,
189+ op: const [
190+ operationType,
191+ ],
192+ ),
193+ );
194+
177195 // TODO: Handle observe
178196 case Event ():
179197 // TODO: Implement
0 commit comments