Skip to content

Commit

Permalink
Prepare for breaking change in package:http
Browse files Browse the repository at this point in the history
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 <nbosch@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
  • Loading branch information
natebosch authored and commit-bot@chromium.org committed Jan 15, 2021
1 parent 989e42f commit 58e7e7e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
5 changes: 3 additions & 2 deletions pkg/analysis_server/tool/code_completion/corpus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ Future<CloneResult> _clone(String repo) async {

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

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

bool _hasPubspec(FileSystemEntity f) =>
f is Directory && File(path.join(f.path, 'pubspec.yaml')).existsSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ main(List<String> arguments) async {
String url = options.rest[0];
String data;
if (url.startsWith("http://") || url.startsWith("https://")) {
data = (await http.get(url)).body;
data = (await http.get(Uri.parse(url))).body;
} else {
data = new File(url).readAsStringSync();
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/nnbd_migration/test/migration_cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
}

Future assertPreviewServerResponsive(String url) async {
var response = await httpGet(url);
var response = await httpGet(Uri.parse(url));
assertHttpSuccess(response);
}

Expand Down Expand Up @@ -372,13 +372,13 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {

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

/// Performs an HTTP post, verifying that the response received (if any) is
/// reasonable.
Future<http.Response> httpPost(dynamic url,
Future<http.Response> httpPost(Uri url,
{Map<String, String> headers, dynamic body, Encoding encoding}) {
return checkHttpResponse(
http.post(url, headers: headers, body: body, encoding: encoding));
Expand All @@ -399,7 +399,7 @@ mixin _MigrationCliTestMethods on _MigrationCliTestBase {
await callback(url);
});
// Server should be stopped now
expect(httpGet(url), throwsA(anything));
expect(httpGet(Uri.parse(url)), throwsA(anything));
assertNormalExit(cliRunner);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/standalone/io/shared_socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ServerWorker {
}
}

Future<String> get(String url) async {
Future<String> get(Uri url) async {
while (true) {
try {
await http.get(url);
Expand All @@ -96,7 +96,7 @@ void client(int port) async {
final futures = <Future>[];
final numAtOnce = 16; // enough to keep the server busy
for (int i = 0; i < numAtOnce; ++i) {
futures.add(get('http://localhost:$port').then((_) {}));
futures.add(get(Uri.http('localhost:$port', '')).then((_) {}));
}
await Future.wait(futures);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/standalone_2/io/shared_socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ServerWorker {
}
}

Future<String> get(String url) async {
Future<String> get(Uri url) async {
while (true) {
try {
await http.get(url);
Expand All @@ -98,7 +98,7 @@ void client(int port) async {
final futures = <Future>[];
final numAtOnce = 16; // enough to keep the server busy
for (int i = 0; i < numAtOnce; ++i) {
futures.add(get('http://localhost:$port').then((_) {}));
futures.add(get(Uri.http('localhost:$port', '')).then((_) {}));
}
await Future.wait(futures);
}
Expand Down
10 changes: 5 additions & 5 deletions tools/bots/get_builder_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const failuresPerConfiguration = 20;

/*late*/ bool useStagingDatabase;

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

/*late*/ String builder;
Expand Down Expand Up @@ -226,7 +226,7 @@ Future<http.Response> runFirestoreQuery(String query) {
'Accept': 'application/json',
'Content-Type': 'application/json'
};
return client.post(queryUrl, headers: headers, body: query);
return client.post(_queryUrl, headers: headers, body: query);
}

String buildQuery() => jsonEncode({
Expand Down
8 changes: 3 additions & 5 deletions tools/bots/post_results_to_pubsub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ ${parser.usage}''');

const resultsPerMessage = 100;

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

main(List<String> args) async {
final parser = new ArgParser();
Expand Down Expand Up @@ -114,7 +112,7 @@ main(List<String> args) async {
]
});
final headers = {'Authorization': 'Bearer $token'};
final postUrl = getPostUrl(project);
final postUrl = _postUrl(project);
final response =
await client.post(postUrl, headers: headers, body: jsonMessage);

Expand Down

0 comments on commit 58e7e7e

Please sign in to comment.