Skip to content

Commit 58e7e7e

Browse files
nateboschcommit-bot@chromium.org
authored andcommitted
Prepare for breaking change in package:http
The `url` argument is changing from `Object`, accepting either `String` or `Uri` at runtime, to `Uri` for better static help. dart-lang/http#507 - Switch to using `Uri` for requests. Where sensible push this type into the signature of the surrounding method. - Make some updated method private where they were unnecessarily public which makes it harder to have confidence when looking for usages. Rename a method with an unnecessary `get` name. Change-Id: Ibf075741d6b9d292349b15f1dc84004981729aca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179368 Auto-Submit: Nate Bosch <[email protected]> Commit-Queue: Jake Macdonald <[email protected]> Reviewed-by: Jake Macdonald <[email protected]>
1 parent 989e42f commit 58e7e7e

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

pkg/analysis_server/tool/code_completion/corpus.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ Future<CloneResult> _clone(String repo) async {
9191

9292
Future<String> _getBody(String url) async => (await _getResponse(url)).body;
9393

94-
Future<http.Response> _getResponse(String url) async => _client
95-
.get(url, headers: const {'User-Agent': 'dart.pkg.completion_metrics'});
94+
Future<http.Response> _getResponse(String url) async =>
95+
_client.get(Uri.parse(url),
96+
headers: const {'User-Agent': 'dart.pkg.completion_metrics'});
9697

9798
bool _hasPubspec(FileSystemEntity f) =>
9899
f is Directory && File(path.join(f.path, 'pubspec.yaml')).existsSync();

pkg/compiler/test/sourcemaps/tools/translate_dart2js_stacktrace.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ main(List<String> arguments) async {
2929
String url = options.rest[0];
3030
String data;
3131
if (url.startsWith("http://") || url.startsWith("https://")) {
32-
data = (await http.get(url)).body;
32+
data = (await http.get(Uri.parse(url))).body;
3333
} else {
3434
data = new File(url).readAsStringSync();
3535
}

pkg/nnbd_migration/test/migration_cli_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
297297
}
298298

299299
Future assertPreviewServerResponsive(String url) async {
300-
var response = await httpGet(url);
300+
var response = await httpGet(Uri.parse(url));
301301
assertHttpSuccess(response);
302302
}
303303

@@ -372,13 +372,13 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
372372

373373
/// Performs an HTTP get, verifying that the response received (if any) is
374374
/// reasonable.
375-
Future<http.Response> httpGet(dynamic url, {Map<String, String> headers}) {
375+
Future<http.Response> httpGet(Uri url, {Map<String, String> headers}) {
376376
return checkHttpResponse(http.get(url, headers: headers));
377377
}
378378

379379
/// Performs an HTTP post, verifying that the response received (if any) is
380380
/// reasonable.
381-
Future<http.Response> httpPost(dynamic url,
381+
Future<http.Response> httpPost(Uri url,
382382
{Map<String, String> headers, dynamic body, Encoding encoding}) {
383383
return checkHttpResponse(
384384
http.post(url, headers: headers, body: body, encoding: encoding));
@@ -399,7 +399,7 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
399399
await callback(url);
400400
});
401401
// Server should be stopped now
402-
expect(httpGet(url), throwsA(anything));
402+
expect(httpGet(Uri.parse(url)), throwsA(anything));
403403
assertNormalExit(cliRunner);
404404
}
405405
}

tests/standalone/io/shared_socket_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ServerWorker {
8282
}
8383
}
8484

85-
Future<String> get(String url) async {
85+
Future<String> get(Uri url) async {
8686
while (true) {
8787
try {
8888
await http.get(url);
@@ -96,7 +96,7 @@ void client(int port) async {
9696
final futures = <Future>[];
9797
final numAtOnce = 16; // enough to keep the server busy
9898
for (int i = 0; i < numAtOnce; ++i) {
99-
futures.add(get('http://localhost:$port').then((_) {}));
99+
futures.add(get(Uri.http('localhost:$port', '')).then((_) {}));
100100
}
101101
await Future.wait(futures);
102102
}

tests/standalone_2/io/shared_socket_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ServerWorker {
8484
}
8585
}
8686

87-
Future<String> get(String url) async {
87+
Future<String> get(Uri url) async {
8888
while (true) {
8989
try {
9090
await http.get(url);
@@ -98,7 +98,7 @@ void client(int port) async {
9898
final futures = <Future>[];
9999
final numAtOnce = 16; // enough to keep the server busy
100100
for (int i = 0; i < numAtOnce; ++i) {
101-
futures.add(get('http://localhost:$port').then((_) {}));
101+
futures.add(get(Uri.http('localhost:$port', '')).then((_) {}));
102102
}
103103
await Future.wait(futures);
104104
}

tools/bots/get_builder_status.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ const failuresPerConfiguration = 20;
2222

2323
/*late*/ bool useStagingDatabase;
2424

25-
String get queryUrl {
26-
var project = useStagingDatabase ? "dart-ci-staging" : "dart-ci";
27-
return 'https://firestore.googleapis.com/v1/'
28-
'projects/$project/databases/(default)/documents:runQuery';
25+
Uri get _queryUrl {
26+
var project = useStagingDatabase ? 'dart-ci-staging' : 'dart-ci';
27+
return Uri.https('firestore.googleapis.com',
28+
'/v1/projects/$project/databases/(default)/documents:runQuery');
2929
}
3030

3131
/*late*/ String builder;
@@ -226,7 +226,7 @@ Future<http.Response> runFirestoreQuery(String query) {
226226
'Accept': 'application/json',
227227
'Content-Type': 'application/json'
228228
};
229-
return client.post(queryUrl, headers: headers, body: query);
229+
return client.post(_queryUrl, headers: headers, body: query);
230230
}
231231

232232
String buildQuery() => jsonEncode({

tools/bots/post_results_to_pubsub.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ ${parser.usage}''');
3030

3131
const resultsPerMessage = 100;
3232

33-
String getPostUrl(String project) {
34-
return 'https://pubsub.googleapis.com/v1/projects/$project'
35-
'/topics/results:publish';
36-
}
33+
Uri _postUrl(String project) => Uri.https(
34+
'pubsub.googleapis.com', 'v1/projects/$project/topics/results:publish');
3735

3836
main(List<String> args) async {
3937
final parser = new ArgParser();
@@ -114,7 +112,7 @@ main(List<String> args) async {
114112
]
115113
});
116114
final headers = {'Authorization': 'Bearer $token'};
117-
final postUrl = getPostUrl(project);
115+
final postUrl = _postUrl(project);
118116
final response =
119117
await client.post(postUrl, headers: headers, body: jsonMessage);
120118

0 commit comments

Comments
 (0)