33// BSD-style license that can be found in the LICENSE file.
44
55import 'dart:async' ;
6+ import 'dart:io' ;
67
78import 'package:async/async.dart' ;
89
910import 'base_client.dart' ;
1011import 'base_request.dart' ;
1112import 'exception.dart' ;
12- import 'io.dart' as io;
1313import 'streamed_response.dart' ;
1414
1515/// A `dart:io` -based HTTP client.
1616///
1717/// This is the default client when running on the command line.
1818class IOClient extends BaseClient {
1919 /// The underlying `dart:io` HTTP client.
20- var _inner;
20+ HttpClient _inner;
2121
2222 /// Creates a new HTTP client.
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]) {
27- io.assertSupported ("IOClient" );
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- }
36- }
23+ IOClient ([HttpClient inner]) : _inner = inner ?? new HttpClient ();
3724
3825 /// Sends an HTTP request and asynchronously returns the response.
3926 Future <StreamedResponse > send (BaseRequest request) async {
@@ -63,7 +50,7 @@ class IOClient extends BaseClient {
6350 return new StreamedResponse (
6451 DelegatingStream .typed/*<List<int>>*/ (response).handleError ((error) =>
6552 throw new ClientException (error.message, error.uri),
66- test: (error) => io. isHttpException ( error) ),
53+ test: (error) => error is HttpException ),
6754 response.statusCode,
6855 contentLength: response.contentLength == - 1
6956 ? null
@@ -73,8 +60,7 @@ class IOClient extends BaseClient {
7360 isRedirect: response.isRedirect,
7461 persistentConnection: response.persistentConnection,
7562 reasonPhrase: response.reasonPhrase);
76- } catch (error) {
77- if (! io.isHttpException (error)) rethrow ;
63+ } on HttpException catch (error) {
7864 throw new ClientException (error.message, error.uri);
7965 }
8066 }
0 commit comments