Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
da7252d
implemented har feature
hrajwade96 Jun 23, 2024
f6f9491
reverting some code
hrajwade96 Jun 23, 2024
a1ba9bd
comments resolved, code refactoring
hrajwade96 Jun 24, 2024
ef3a637
added doc comments for buildHar
hrajwade96 Jun 24, 2024
058e053
exportController moved to method scope
hrajwade96 Jun 24, 2024
ae292ad
httpRequests moved to NetworkController class
hrajwade96 Jun 24, 2024
9d5231b
Merge branch 'master' into export_har_feature
hrajwade96 Jun 26, 2024
1b9e483
code comments resolved
hrajwade96 Jun 26, 2024
0e5cdbb
Merge remote-tracking branch 'origin/export_har_feature' into export_…
hrajwade96 Jun 26, 2024
5c306c1
removed pages, pageref and serverIPAddress
hrajwade96 Jun 27, 2024
5d8fc75
added header size and body size, creatorVersion set
hrajwade96 Jun 27, 2024
16faad7
organized imports
hrajwade96 Jun 27, 2024
f843862
Merge remote-tracking branch 'upstream/master' into export_har_feature
hrajwade96 Jul 4, 2024
1c4442c
removed mixin and override, changed year to 2024, renamed variable
hrajwade96 Jul 8, 2024
8c08441
moved constants, converted to enum
hrajwade96 Jul 8, 2024
625b452
downloadAsHar moved back to analytics constants
hrajwade96 Jul 11, 2024
3dd0274
added copyright header
hrajwade96 Jul 11, 2024
0261ab7
HarNetworkData model class added, serialisation and de-serialisation …
hrajwade96 Jul 12, 2024
b77c454
removed testing code
hrajwade96 Jul 12, 2024
484e9f2
added copyright, created enum, condition checking improvements, Used …
hrajwade96 Jul 16, 2024
f504b18
import optimised, used Serializable mixin
hrajwade96 Jul 16, 2024
258e34e
Merge remote-tracking branch 'upstream/master' into export_har_feature
hrajwade96 Jul 16, 2024
f741882
minor fix
hrajwade96 Jul 16, 2024
eb7f848
replaced dynamic with Object? in har network data, minor fix
hrajwade96 Jul 16, 2024
a608451
used enum
hrajwade96 Jul 16, 2024
b734dc3
header and dart docs added
hrajwade96 Jul 16, 2024
449f9e6
used HarNetworkData
hrajwade96 Jul 16, 2024
0175330
print removed, scope added to class name in dart docs
hrajwade96 Jul 17, 2024
6c13f54
dart docs improvements
hrajwade96 Jul 17, 2024
f332b40
removed -2ms
hrajwade96 Jul 17, 2024
70d9468
renamed exception variable
hrajwade96 Jul 17, 2024
6f03ce2
changed dynamic to Object?
hrajwade96 Jul 17, 2024
6c73e28
removed ignore, added cast everywhere, changed dynamic to Object?
hrajwade96 Jul 17, 2024
fb4fd58
removed ignore, added cast, added trailing comma
hrajwade96 Jul 17, 2024
0a0b4be
used isNullOrEmpty
hrajwade96 Jul 17, 2024
21f6a5f
import fixed
hrajwade96 Jul 18, 2024
2d12a0d
created new class HarDataEntry for code separation
hrajwade96 Jul 18, 2024
df0b56f
used values from constants, added dart docs
hrajwade96 Jul 19, 2024
23295fc
added constants
hrajwade96 Jul 19, 2024
1398c0e
improved code readability
hrajwade96 Jul 19, 2024
7bbdf80
replaced dynamic with Object?
hrajwade96 Jul 19, 2024
e1c9791
added type to list
hrajwade96 Jul 19, 2024
c0cb621
used values directly, removed unnecessary null checks
hrajwade96 Jul 20, 2024
daccfde
used values directly, fixed typo
hrajwade96 Jul 20, 2024
2692ea1
restructured har creation, implemented toJson
hrajwade96 Jul 20, 2024
01f5122
used values from constants
hrajwade96 Jul 20, 2024
c5c1842
changed dynamic to Object?, dart docs fix, added header
hrajwade96 Jul 25, 2024
2734fcb
added comments for explanation
hrajwade96 Jul 25, 2024
fb10b26
minor fixes
hrajwade96 Jul 26, 2024
8a65da8
added tests for HarDataEntry
hrajwade96 Jul 26, 2024
6443964
code reformatted, updated release notes
hrajwade96 Jul 26, 2024
89dae77
Merge branch 'master' into export_har_feature
hrajwade96 Jul 26, 2024
b26b833
minor change
hrajwade96 Jul 27, 2024
6d4177b
Merge remote-tracking branch 'origin/export_har_feature' into export_…
hrajwade96 Jul 27, 2024
83b4a3f
reverting change
hrajwade96 Jul 29, 2024
7d211fd
added missing trailing comma
hrajwade96 Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ enum NetworkEventKeys {
version,
creator,
name,
creatorVersion,
pages,
startedDateTime,
id,
Expand Down Expand Up @@ -56,6 +55,7 @@ enum NetworkEventKeys {
expires,
httpOnly,
secure,
reasonPhrase,
}

class NetworkEventDefaults {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Map<String, Object?> buildHar(List<DartIOHttpRequestData> httpRequests) {
// Build the creator
final creator = <String, Object?>{
NetworkEventKeys.name.name: NetworkEventDefaults.creatorName,
NetworkEventKeys.creatorVersion.name: devToolsVersion,
NetworkEventKeys.version.name: devToolsVersion,
};

// Build the entries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
Comment thread
hrajwade96 marked this conversation as resolved.

import '../../shared/http/http_request_data.dart';
Expand Down Expand Up @@ -133,7 +137,7 @@ class HarDataEntry {
// Response
NetworkEventKeys.response.name: <String, Object?>{
NetworkEventKeys.status.name: e.status,
NetworkEventKeys.statusText.name: '',
NetworkEventKeys.statusText.name: e.general[NetworkEventKeys.reasonPhrase.name]??'',
Comment thread
kenzieschmoll marked this conversation as resolved.
Outdated
NetworkEventKeys.httpVersion.name:
NetworkEventDefaults.responseHttpVersion,
NetworkEventKeys.cookies.name: responseCookies,
Expand Down Expand Up @@ -164,15 +168,19 @@ class HarDataEntry {

// Custom fields
// har spec requires underscore to be added for custom fields, hence removing them
// Note: the 'isolateId' field is kept empty because DartIOHttpRequestData does not expose it
// (but it is required by HttpProfileRequestRef.parse)
NetworkEventCustomFieldKeys.isolateId: '',
Comment thread
kenzieschmoll marked this conversation as resolved.
NetworkEventCustomFieldKeys.id: e.id,
NetworkEventCustomFieldKeys.startTime:
e.startTimestamp.microsecondsSinceEpoch,
// Note: The 'events' field is kept empty because DartIOHttpRequestData does not expose it
// (but it is required by HttpProfileRequestRef.parse)
NetworkEventCustomFieldKeys.events: [],
Comment thread
kenzieschmoll marked this conversation as resolved.
};
}

/// Converts the HAR data entry back to [DartIOHttpRequestData].
/// Returns the original [DartIOHttpRequestData] that this HAR entry was created from or parsed into.
DartIOHttpRequestData toDartIOHttpRequest() {
return request;
}
Expand Down Expand Up @@ -204,7 +212,7 @@ class HarDataEntry {
return transformedHeaders;
}

// Convert list of headers to map
/// Convert list of headers to map
static void _convertHeaders(Map<String, Object?> requestData) {
final reqData =
requestData[NetworkEventKeys.request.name] as Map<String, Object?>;
Expand All @@ -225,7 +233,7 @@ class HarDataEntry {
}
}

// Removing underscores from custom fields
/// Removing underscores from custom fields
static Map<String, Object?> _remapCustomFieldKeys(
Map<String, Object?> originalMap,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DartIOHttpRequestData extends NetworkRequest {
}

factory DartIOHttpRequestData.fromJson(
Map<String, dynamic> modifiedRequestData,
Map<String, Object?> modifiedRequestData,
Map<String, Object?>? requestPostData,
Map<String, Object?>? responseContent,
) {
Expand Down
45 changes: 44 additions & 1 deletion packages/devtools_app/test/network/har_network_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import 'dart:convert';
Comment thread
hrajwade96 marked this conversation as resolved.
import 'dart:io';

import 'package:devtools_app/src/screens/network/constants.dart';
import 'package:devtools_app/src/screens/network/har_data_entry.dart';
import 'package:devtools_app/src/screens/network/har_network_data.dart';

import 'package:flutter_test/flutter_test.dart';

void main() {
final file = File('test/network/sample_requests.json');
final fileContent = file.readAsStringSync();
final jsonData = jsonDecode(fileContent);
final jsonData = jsonDecode(fileContent) as Map<String, Object?>;

group('HarNetworkData', () {
test('toJson serializes correctly', () {
Expand Down Expand Up @@ -54,4 +56,45 @@ void main() {
expect(entry?['comment'], '');
});
});

group('HarDataEntry', () {
test('fromJson parses correctly', () {
final entryJson =
((jsonData['log'] as Map<String, Object?>)['entries'] as List).first
as Map<String, Object?>;
final harDataEntry = HarDataEntry.fromJson(entryJson);

expect(harDataEntry.request.uri.toString(),
'https://jsonplaceholder.typicode.com/albums/1');
expect(harDataEntry.request.method, 'GET');
expect(harDataEntry.request.requestHeaders, isNotEmpty);
expect(harDataEntry.request.requestCookies, isEmpty);
});

test('toJson serializes correctly', () {
final entryJson =
((jsonData['log'] as Map<String, Object?>)['entries'] as List).first
as Map<String, Object?>;
final harDataEntry = HarDataEntry.fromJson(entryJson);
final json = HarDataEntry.toJson(harDataEntry.request);

expect(json['startedDateTime'], '2024-07-11T13:19:35.156Z');
expect(json['request'], isNotNull);
final request = json['request'] as Map<String, Object?>?;
expect(request?['method'], 'GET');
expect(request?['url'], 'https://jsonplaceholder.typicode.com/albums/1');
expect(request?['httpVersion'], 'HTTP/1.1');
expect(request?['cookies'], isEmpty);

expect(json['cache'], isEmpty);
final timings = json['timings'] as Map<String, Object?>?;
expect(timings?['blocked'], NetworkEventDefaults.blocked);
expect(timings?['dns'], NetworkEventDefaults.dns);
expect(timings?['connect'], NetworkEventDefaults.connect);
expect(timings?['send'], 1);
expect(timings?['receive'], 1);
expect(timings?['ssl'], NetworkEventDefaults.ssl);
expect(json['comment'], '');
});
});
}
2 changes: 1 addition & 1 deletion packages/devtools_app/test/network/sample_requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.2",
"creator": {
"name": "devtools",
"creatorVersion": "2.38.0-dev.0"
"version": "2.38.0-dev.0"
},
"entries": [
{
Expand Down