Skip to content

Commit 04777ac

Browse files
authored
Add a skeleton "http_profile" package (#1036)
1 parent b9389fe commit 04777ac

File tree

9 files changed

+179
-18
lines changed

9 files changed

+179
-18
lines changed

.github/workflows/dart.yml

Lines changed: 62 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/http_profile/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Skeleton class and test definitions.

pkgs/http_profile/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2023, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/http_profile/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
An **experimental** package that allows HTTP clients outside of the Dart SDK
2+
to integrate with the DevTools Network tab.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
/// A record of debugging information about an HTTP request.
8+
final class HttpClientRequestProfile {
9+
/// Whether HTTP profiling is enabled or not.
10+
///
11+
/// The value can be changed programmatically or through the DevTools Network
12+
/// UX.
13+
static bool get profilingEnabled => HttpClient.enableTimelineLogging;
14+
static set profilingEnabled(bool enabled) =>
15+
HttpClient.enableTimelineLogging = enabled;
16+
17+
String? requestMethod;
18+
String? requestUri;
19+
20+
HttpClientRequestProfile._();
21+
22+
/// If HTTP profiling is enabled, returns
23+
/// a [HttpClientRequestProfile] otherwise returns `null`.
24+
static HttpClientRequestProfile? profile() {
25+
// Always return `null` in product mode so that the
26+
// profiling code can be tree shaken away.
27+
if (const bool.fromEnvironment('dart.vm.product') || !profilingEnabled) {
28+
return null;
29+
}
30+
final requestProfile = HttpClientRequestProfile._();
31+
return requestProfile;
32+
}
33+
}

pkgs/http_profile/mono_pkg.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sdk:
2+
- pubspec
3+
- dev
4+
5+
stages:
6+
- analyze_and_format:
7+
- analyze: --fatal-infos
8+
- format:
9+
sdk:
10+
- dev
11+
- unit_test:
12+
- test: --platform vm
13+
os:
14+
- linux

pkgs/http_profile/pubspec.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: http_profile
2+
description: >-
3+
A library used by HTTP client authors to integrate with the DevTools
4+
Network tab.
5+
publish_to: none
6+
repository: https://github.com/dart-lang/http/tree/master/pkgs/http_profile
7+
8+
environment:
9+
sdk: ^3.0.0
10+
11+
dependencies:
12+
test: ^1.24.9
13+
14+
dev_dependencies:
15+
dart_flutter_team_lints: ^2.1.1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
7+
import 'package:http_profile/http_profile.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
test('profiling enabled', () async {
12+
HttpClientRequestProfile.profilingEnabled = true;
13+
expect(HttpClient.enableTimelineLogging, true);
14+
expect(HttpClientRequestProfile.profile(), isNotNull);
15+
});
16+
17+
test('profiling disabled', () async {
18+
HttpClientRequestProfile.profilingEnabled = false;
19+
expect(HttpClient.enableTimelineLogging, false);
20+
expect(HttpClientRequestProfile.profile(), isNull);
21+
});
22+
}

tool/ci.sh

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)