diff --git a/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoInspectorRequest.java b/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoInspectorRequest.java index 00459d9..85181f3 100644 --- a/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoInspectorRequest.java +++ b/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoInspectorRequest.java @@ -40,8 +40,8 @@ public String method() { @Override public byte[] body() throws IOException { if (map.get("body") != null) { - byte[] bytes = new byte[]{}; List body = ((List) map.get("body")); + byte[] bytes = new byte[body.size()]; for (int i = 0; i < body.size(); i++) { bytes[i] = body.get(i).byteValue(); } diff --git a/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoPlugin.java b/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoPlugin.java index a16fb9e..bea2b43 100644 --- a/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoPlugin.java +++ b/android/src/main/java/com/brianegan/flutterstetho/FlutterStethoPlugin.java @@ -68,8 +68,8 @@ public void onMethodCall(final MethodCall call, Result result) { case "interpretResponseStream": interpretResponseStream(((String) call.arguments)); break; - case "onData": - onData((Map) call.arguments); + case "onDataReceived": + onDataReceived((Map) call.arguments); break; case "onDone": onDone((String) call.arguments); @@ -97,7 +97,7 @@ private void onDone(String id) { } } - private void onData(Map arguments) { + private void onDataReceived(Map arguments) { final String dataId = ((String) arguments.get("id")); final byte[] data = ((byte[]) arguments.get("data")); final LinkedBlockingQueue queue = queues.get(dataId); @@ -106,6 +106,7 @@ private void onData(Map arguments) { } catch (InterruptedException e) { e.printStackTrace(); } + mEventReporter.dataReceived(dataId,data.length,data.length); } private void responseHeadersReceived(Map arguments) { diff --git a/lib/src/http_client.dart b/lib/src/http_client.dart index 3fcda18..57339de 100644 --- a/lib/src/http_client.dart +++ b/lib/src/http_client.dart @@ -123,24 +123,43 @@ class StethoHttpClient implements HttpClient { int port, String path, ) async { - return _wrapResponse(await client.open(method, host, port, path)); + Uri uri = Uri(host: host,port: port, path: path); + return await openUrl(method, uri); } @override Future openUrl(String method, Uri url) async { return client.openUrl(method, url).then((request) { final wrapped = _wrapResponse(request); - - scheduleMicrotask(() { - MethodChannelController.requestWillBeSent( - new FlutterStethoInspectorRequest( - url: request.uri.toString(), - headers: headersToMap(request.headers), - method: request.method, - id: wrapped.id, - ), - ); - }); + List body = []; + if (method.toLowerCase() != 'post' && method.toLowerCase() != 'put'){ + scheduleMicrotask(() { + MethodChannelController.requestWillBeSent( + new FlutterStethoInspectorRequest( + url: request.uri.toString(), + headers: headersToMap(request.headers), + method: request.method, + id: wrapped.id, + body: body, + ), + ); + }); + } else { + wrapped.stream.listen((onData) { + body.addAll(onData); + scheduleMicrotask(() { + MethodChannelController.requestWillBeSent( + new FlutterStethoInspectorRequest( + url: request.uri.toString(), + headers: headersToMap(request.headers), + method: request.method, + id: wrapped.id, + body: body, + ), + ); + }); + }); + } return wrapped; }); diff --git a/lib/src/http_client_request.dart b/lib/src/http_client_request.dart index 3e10a00..e7f9c14 100644 --- a/lib/src/http_client_request.dart +++ b/lib/src/http_client_request.dart @@ -10,6 +10,8 @@ import 'package:flutter_stetho/src/utils.dart'; class StethoHttpClientRequest implements HttpClientRequest { final HttpClientRequest request; final String id; + final StreamController> _streamController = StreamController.broadcast(); + Stream get stream => _streamController.stream.asBroadcastStream(); StethoHttpClientRequest( this.request, @@ -18,6 +20,7 @@ class StethoHttpClientRequest implements HttpClientRequest { @override void add(List data) { + _streamController.add(data); request.add(data); } @@ -28,13 +31,14 @@ class StethoHttpClientRequest implements HttpClientRequest { @override Future addStream(Stream> stream) { - return request.addStream(stream); + var newStream = stream.asBroadcastStream(); + newStream.listen((onData)=> _streamController.add(onData)); + return request.addStream(newStream); } @override Future close() async { final response = await request.close(); - MethodChannelController.responseHeadersReceived( new FlutterStethoInspectorResponse( url: request.uri.toString(), @@ -122,15 +126,23 @@ class StethoHttpClientRequest implements HttpClientRequest { @override void writeAll(Iterable objects, [String separator = ""]) { request.writeAll(objects, separator); + String data = objects.map((object) => object.toString()).join(separator); + _streamController.add(data.codeUnits); } @override void writeCharCode(int charCode) { request.writeCharCode(charCode); + _streamController.add([charCode]); } @override void writeln([Object obj = ""]) { request.writeln(obj); + if (obj is String){ + _streamController.add(obj.codeUnits); + } else { + _streamController.add(obj.toString().codeUnits); + } } } diff --git a/lib/src/method_channel_controller.dart b/lib/src/method_channel_controller.dart index 9508157..abea086 100644 --- a/lib/src/method_channel_controller.dart +++ b/lib/src/method_channel_controller.dart @@ -24,8 +24,8 @@ class MethodChannelController { static Future responseReadFailed(List idError) => _channel.invokeMethod('responseReadFailed', idError); - static Future onData(Map map) => - _channel.invokeMethod('onData', map); + static Future onDataReceived(Map map) => + _channel.invokeMethod('onDataReceived', map); static Future onDone(String id) => _channel.invokeMethod('onDone', id); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index f327902..9a40a08 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -10,7 +10,7 @@ import 'package:flutter_stetho/src/method_channel_controller.dart'; StreamTransformer, List> createResponseTransformer(String id) { return new StreamTransformer.fromHandlers(handleData: (data, sink) { sink.add(data); - MethodChannelController.onData({"data": data, "id": id}); + MethodChannelController.onDataReceived({"data": data, "id": id}); }, handleError: (error, stacktrace, sink) { sink.addError(error, stacktrace); MethodChannelController.responseReadFailed([id, error.toString()]);