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

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

Issue 415373002: Limit pub to 16 concurrent HTTP requests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | « no previous file | sdk/lib/_internal/pub/test/test_pub.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 24dbacbeafe66a7900549a8c3a022f463336431f..4fe118eb25c238e8df4dc24be2c8b0757e6f8982 100644
--- a/sdk/lib/_internal/pub/lib/src/http.dart
+++ b/sdk/lib/_internal/pub/lib/src/http.dart
@@ -10,6 +10,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
+import 'package:http_throttle/http_throttle.dart';
import 'io.dart';
import 'log.dart' as log;
@@ -38,13 +39,13 @@ final PUB_API_HEADERS = const {'Accept': 'application/vnd.pub.v2+json'};
/// This also adds a 30-second timeout to every request. This can be configured
/// on a per-request basis by setting the 'Pub-Request-Timeout' header to the
/// desired number of milliseconds, or to "None" to disable the timeout.
-class PubHttpClient extends http.BaseClient {
+class _PubHttpClient extends http.BaseClient {
final _requestStopwatches = new Map<http.BaseRequest, Stopwatch>();
- http.Client inner;
+ http.Client _inner;
- PubHttpClient([http.Client inner])
- : this.inner = inner == null ? new http.Client() : inner;
+ _PubHttpClient([http.Client inner])
+ : this._inner = inner == null ? new http.Client() : inner;
Future<http.StreamedResponse> send(http.BaseRequest request) {
_requestStopwatches[request] = new Stopwatch()..start();
@@ -67,7 +68,7 @@ class PubHttpClient extends http.BaseClient {
timeoutLength = int.parse(timeoutString);
}
- var future = inner.send(request).then((streamedResponse) {
+ var future = _inner.send(request).then((streamedResponse) {
_logResponse(streamedResponse);
var status = streamedResponse.statusCode;
@@ -191,8 +192,15 @@ class PubHttpClient extends http.BaseClient {
}
}
+/// The [_PubHttpClient] wrapped by [httpClient].
+final _pubClient = new _PubHttpClient();
+
/// The HTTP client to use for all HTTP requests.
-final httpClient = new PubHttpClient();
+final httpClient = new ThrottleClient(16, _pubClient);
+
+/// The underlying HTTP client wrapped by [httpClient].
+http.Client get innerHttpClient => _pubClient._inner;
+set innerHttpClient(http.Client client) => _pubClient._inner = client;
/// Handles a successful JSON-formatted response from pub.dartlang.org.
///
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698