Skip to content

Commit ccdf945

Browse files
committed
network: Fix bad HAR data
1 parent e41c353 commit ccdf945

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/devtools_app/lib/src/screens/network/har_data_entry.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:convert';
66
import 'dart:typed_data';
77

88
import '../../screens/network/utils/http_utils.dart';
9+
import '../../shared/http/constants.dart' as shared_http;
910
import '../../shared/http/http_request_data.dart';
1011
import 'constants.dart';
1112

@@ -45,6 +46,16 @@ class HarDataEntry {
4546
final requestPostData = responseData[NetworkEventKeys.postData.name];
4647
final responseContent = responseData[NetworkEventKeys.content.name];
4748

49+
final statusValue = responseData[NetworkEventKeys.status.name];
50+
int? statusCode;
51+
if (statusValue is int) {
52+
statusCode = statusValue;
53+
} else if (statusValue is String) {
54+
statusCode = int.tryParse(statusValue);
55+
}
56+
responseData[shared_http.HttpRequestDataKeys.statusCode.name] =
57+
statusCode ?? -1;
58+
4859
return HarDataEntry(
4960
DartIOHttpRequestData.fromJson(
5061
modifiedRequestData,
@@ -148,7 +159,7 @@ class HarDataEntry {
148159
},
149160
// Response
150161
NetworkEventKeys.response.name: <String, Object?>{
151-
NetworkEventKeys.status.name: e.status,
162+
NetworkEventKeys.status.name: int.tryParse(e.status ?? '') ?? -1,
152163
NetworkEventKeys.statusText.name:
153164
e.general[NetworkEventKeys.reasonPhrase.name] ?? '',
154165
NetworkEventKeys.httpVersion.name:

packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ TODO: Remove this section if there are not any updates.
4040

4141
## Network profiler updates
4242

43-
TODO: Remove this section if there are not any updates.
43+
- Fixed exported response status in HAR files so that they parse as integers instead of strings. [TODO](https://github.com/flutter/devtools/pull/TODO)
4444

4545
## Logging updates
4646

packages/devtools_app/test/screens/network/har_network_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void main() {
7171
expect(harDataEntry.request.method, 'GET');
7272
expect(harDataEntry.request.requestHeaders, isNotEmpty);
7373
expect(harDataEntry.request.requestCookies, isEmpty);
74+
expect(harDataEntry.request.status, '200');
7475
});
7576

7677
test('toJson serializes correctly', () {
@@ -89,6 +90,11 @@ void main() {
8990
expect(request?['cookies'], isEmpty);
9091

9192
expect(json['cache'], isEmpty);
93+
final response = json['response'] as Map<String, Object?>?;
94+
expect(response, isNotNull);
95+
expect(response?['status'], 200);
96+
expect(response?['statusText'], '');
97+
9298
final timings = json['timings'] as Map<String, Object?>?;
9399
expect(timings?['blocked'], NetworkEventDefaults.blocked);
94100
expect(timings?['dns'], NetworkEventDefaults.dns);

0 commit comments

Comments
 (0)