Skip to content

Commit e9885f3

Browse files
committed
refactor(binding_http): simplify input data handling
1 parent 89b223d commit e9885f3

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

lib/src/binding_http/http_client.dart

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,15 @@ final class HttpClient implements ProtocolClient {
188188
Future<StreamedResponse> _createRequest(
189189
Form form,
190190
OperationType operationType,
191-
String? payload,
191+
Content? content,
192192
) async {
193193
final requestMethod =
194194
HttpRequestMethod.getRequestMethod(form, operationType);
195195
final Uri uri = form.resolvedHref;
196196

197197
final request = Request(requestMethod.methodName, uri)
198-
..headers.addAll(_getHeadersFromForm(form));
199-
200-
if (payload != null) {
201-
request.body = payload;
202-
}
198+
..headers.addAll(_getHeadersFromForm(form))
199+
..bodyBytes = await content?.toByteList() ?? [];
203200

204201
await _applyCredentialsFromForm(request, form);
205202

@@ -244,12 +241,6 @@ final class HttpClient implements ProtocolClient {
244241
return headers;
245242
}
246243

247-
Future<String> _getInputFromContent(Content content) async {
248-
final inputBuffer =
249-
await content.body.expand((element) => element).toList();
250-
return utf8.decoder.convert(inputBuffer);
251-
}
252-
253244
Content _contentFromResponse(Form form, StreamedResponse response) {
254245
final type = response.headers['Content-Type'] ?? form.contentType;
255246
final responseStream = response.stream.asBroadcastStream()
@@ -259,9 +250,8 @@ final class HttpClient implements ProtocolClient {
259250

260251
@override
261252
Future<Content> invokeResource(Form form, Content content) async {
262-
final input = await _getInputFromContent(content);
263253
final response =
264-
await _createRequest(form, OperationType.invokeaction, input);
254+
await _createRequest(form, OperationType.invokeaction, content);
265255
return _contentFromResponse(form, response);
266256
}
267257

@@ -284,8 +274,7 @@ final class HttpClient implements ProtocolClient {
284274

285275
@override
286276
Future<void> writeResource(Form form, Content content) async {
287-
final input = await _getInputFromContent(content);
288-
await _createRequest(form, OperationType.writeproperty, input);
277+
await _createRequest(form, OperationType.writeproperty, content);
289278
}
290279

291280
@override

0 commit comments

Comments
 (0)