Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Unified Diff: sdk/lib/_internal/pub/lib/src/http.dart

Issue 16351003: Move pub over to using the pub.dartlang.org API v2. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/hosted_source.dart ('k') | sdk/lib/_internal/pub/lib/src/pubspec.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/http.dart
diff --git a/sdk/lib/_internal/pub/lib/src/http.dart b/sdk/lib/_internal/pub/lib/src/http.dart
index 00fa9522faac49dd50bc3565c09caf60d097ce72..e7da34c6c6189989e31d0d17d637bf2770ff3487 100644
--- a/sdk/lib/_internal/pub/lib/src/http.dart
+++ b/sdk/lib/_internal/pub/lib/src/http.dart
@@ -14,6 +14,7 @@ import 'package:http/http.dart' as http;
import 'io.dart';
import 'log.dart' as log;
import 'oauth2.dart' as oauth2;
+import 'sdk.dart' as sdk;
import 'utils.dart';
// TODO(nweiz): make this configurable
@@ -24,6 +25,13 @@ final HTTP_TIMEOUT = 30 * 1000;
/// Headers and field names that should be censored in the log output.
final _CENSORED_FIELDS = const ['refresh_token', 'authorization'];
+/// Headers required for pub.dartlang.org API requests.
+///
+/// The Accept header tells pub.dartlang.org which version of the API we're
+/// expecting, so it can either serve that version or give us a 406 error if
+/// it's not supported.
+final PUB_API_HEADERS = const {'Accept': 'application/vnd.pub.v2+json'};
+
/// Whether dart:io's SecureSocket has been initialized with pub's resources
/// yet.
bool _initializedSecureSocket = false;
@@ -54,8 +62,6 @@ class PubHttpClient extends http.BaseClient {
stackTrace = localStackTrace;
}
- // TODO(nweiz): Ideally the timeout would extend to reading from the
- // response input stream, but until issue 3657 is fixed that's not feasible.
return timeout(inner.send(request).then((streamedResponse) {
_logResponse(streamedResponse);
@@ -69,6 +75,13 @@ class PubHttpClient extends http.BaseClient {
return streamedResponse;
}
+ if (status == 406 &&
+ request.headers['Accept'] == PUB_API_HEADERS['Accept']) {
+ fail("Pub ${sdk.version} is incompatible with the current version of "
+ "${request.url.host}.\n"
+ "Upgrade pub to the latest version and try again.");
+ }
+
return http.Response.fromStream(streamedResponse).then((response) {
throw new PubHttpException(response);
});
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/hosted_source.dart ('k') | sdk/lib/_internal/pub/lib/src/pubspec.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698