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

Side by Side Diff: pkg/http/lib/src/io_client.dart

Issue 299483002: Support a user-supplied dart:io client in pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/io.dart ('k') | pkg/http/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library io_client; 5 library io_client;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:stack_trace/stack_trace.dart'; 9 import 'package:stack_trace/stack_trace.dart';
10 10
11 import 'base_client.dart'; 11 import 'base_client.dart';
12 import 'base_request.dart'; 12 import 'base_request.dart';
13 import 'exception.dart'; 13 import 'exception.dart';
14 import 'io.dart' as io; 14 import 'io.dart' as io;
15 import 'streamed_response.dart'; 15 import 'streamed_response.dart';
16 16
17 /// A `dart:io`-based HTTP client. This is the default client. 17 /// A `dart:io`-based HTTP client. This is the default client.
18 class IOClient extends BaseClient { 18 class IOClient extends BaseClient {
19 /// The underlying `dart:io` HTTP client. 19 /// The underlying `dart:io` HTTP client.
20 var _inner; 20 var _inner;
21 21
22 /// Creates a new HTTP client. 22 /// Creates a new HTTP client.
23 IOClient() { 23 ///
24 /// [innerClient] must be a `dart:io` HTTP client. If it's not passed, a
25 /// default one will be instantiated.
26 IOClient([innerClient]) {
24 io.assertSupported("IOClient"); 27 io.assertSupported("IOClient");
25 _inner = io.newHttpClient(); 28 if (innerClient != null) {
29 // TODO(nweiz): remove this assert when we can type [innerClient]
30 // properly.
31 assert(io.isHttpClient(innerClient));
32 _inner = innerClient;
33 } else {
34 _inner = io.newHttpClient();
35 }
26 } 36 }
27 37
28 /// Sends an HTTP request and asynchronously returns the response. 38 /// Sends an HTTP request and asynchronously returns the response.
29 Future<StreamedResponse> send(BaseRequest request) { 39 Future<StreamedResponse> send(BaseRequest request) {
30 var stream = request.finalize(); 40 var stream = request.finalize();
31 41
32 return Chain.track(_inner.openUrl(request.method, request.url)) 42 return Chain.track(_inner.openUrl(request.method, request.url))
33 .then((ioRequest) { 43 .then((ioRequest) {
34 var contentLength = request.contentLength == null ? 44 var contentLength = request.contentLength == null ?
35 -1 : request.contentLength; 45 -1 : request.contentLength;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 }); 77 });
68 } 78 }
69 79
70 /// Closes the client. This terminates all active connections. If a client 80 /// Closes the client. This terminates all active connections. If a client
71 /// remains unclosed, the Dart process may not terminate. 81 /// remains unclosed, the Dart process may not terminate.
72 void close() { 82 void close() {
73 if (_inner != null) _inner.close(force: true); 83 if (_inner != null) _inner.close(force: true);
74 _inner = null; 84 _inner = null;
75 } 85 }
76 } 86 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/io.dart ('k') | pkg/http/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698