Skip to content

Commit 0dff44e

Browse files
authored
Correctly process large HTTP responses in network profiler (#2602)
The network profiler was assuming that a response body would only ever consist of a single chunk. This was resulting in us trying to decode a partial response, causing a FormatException to be thrown and halting processing of HTTP events. This change stitches together all of the response body events for a given response before trying to decode it. In addition, the FormatException is caught and ignored in order to allow for non-UTF8 responses. Fixes both #2398 and #2480
1 parent b05cdfe commit 0dff44e

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

packages/devtools_app/lib/src/http/http_request_data.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,24 @@ class HttpRequestData extends NetworkRequest {
6969
}
7070
}
7171

72+
// Stitch together response as it may have been sent in multiple chunks.
73+
final encodedData = <int>[];
7274
for (final event in responseEvents) {
7375
final traceEvent = TraceEvent(event);
7476
// TODO(kenz): do we need to do something with the other response events
7577
// (phases 'b' and 'e')?
7678
if (traceEvent.phase == TraceEvent.asyncInstantPhase &&
7779
traceEvent.name == 'Response body') {
78-
final encodedData = (traceEvent.args['data'] as List).cast<int>();
80+
encodedData.addAll((traceEvent.args['data'] as List).cast<int>());
81+
}
82+
}
83+
84+
try {
85+
if (encodedData.isNotEmpty) {
7986
responseBody = utf8.decode(encodedData);
80-
break;
8187
}
88+
} on FormatException {
89+
// Non-UTF8 response.
8290
}
8391

8492
final data = HttpRequestData._(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
23
#include "ephemeral/Flutter-Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
23
#include "ephemeral/Flutter-Generated.xcconfig"

packages/devtools_app/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ packages:
554554
source: hosted
555555
version: "1.2.0"
556556
string_scanner:
557-
dependency: transitive
557+
dependency: "direct main"
558558
description:
559559
name: string_scanner
560560
url: "https://pub.dartlang.org"
@@ -709,4 +709,4 @@ packages:
709709
version: "2.2.1"
710710
sdks:
711711
dart: ">=2.12.0-0.0 <3.0.0"
712-
flutter: ">=1.22.0 <2.0.0"
712+
flutter: ">=1.22.0"

0 commit comments

Comments
 (0)