Chromium Code Reviews| 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..f68e5a70f1d1ddb58d97a9ef038efb3dd6f935da 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/http.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/http.dart |
| @@ -8,12 +8,14 @@ library pub.http; |
| import 'dart:async'; |
| import 'dart:io'; |
| import 'dart:json' as json; |
| +import 'dart:typed_data'; |
|
Bob Nystrom
2013/06/04 20:21:41
Remove this?
nweiz
2013/06/04 21:04:17
Done.
|
| 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 +26,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 = {'Accept': 'application/vnd.pub.v2+json'}; |
|
Bob Nystrom
2013/06/04 20:21:41
final -> const
nweiz
2013/06/04 21:04:17
Done.
|
| + |
| /// Whether dart:io's SecureSocket has been initialized with pub's resources |
| /// yet. |
| bool _initializedSecureSocket = false; |
| @@ -54,8 +63,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 +76,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 " |
| + "pub.dartlang.org.\n" |
| + "Upgrade pub to the latest version and try again."); |
| + } |
| + |
| return http.Response.fromStream(streamedResponse).then((response) { |
| throw new PubHttpException(response); |
| }); |