OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 http.io; | 5 library http.io; |
6 | 6 |
7 @MirrorsUsed(targets: const ['dart.io.HttpClient', 'dart.io.HttpException', | 7 @MirrorsUsed(targets: const ['dart.io.HttpClient', 'dart.io.HttpException', |
8 'dart.io.File']) | 8 'dart.io.File']) |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 /// Creates a new `dart:io` HttpClient instance. | 37 /// Creates a new `dart:io` HttpClient instance. |
38 newHttpClient() => _httpClient.newInstance(const Symbol(''), []).reflectee; | 38 newHttpClient() => _httpClient.newInstance(const Symbol(''), []).reflectee; |
39 | 39 |
40 /// Creates a new `dart:io` File instance with the given [path]. | 40 /// Creates a new `dart:io` File instance with the given [path]. |
41 newFile(String path) => _file.newInstance(const Symbol(''), [path]).reflectee; | 41 newFile(String path) => _file.newInstance(const Symbol(''), [path]).reflectee; |
42 | 42 |
43 /// Returns whether [error] is a `dart:io` HttpException. | 43 /// Returns whether [error] is a `dart:io` HttpException. |
44 bool isHttpException(error) => reflect(error).type.isSubtypeOf(_httpException); | 44 bool isHttpException(error) => reflect(error).type.isSubtypeOf(_httpException); |
45 | 45 |
| 46 /// Returns whether [client] is a `dart:io` HttpClient. |
| 47 bool isHttpClient(client) => reflect(client).type.isSubtypeOf(_httpClient); |
| 48 |
46 /// Tries to load `dart:io` and returns `null` if it fails. | 49 /// Tries to load `dart:io` and returns `null` if it fails. |
47 LibraryMirror _getLibrary() { | 50 LibraryMirror _getLibrary() { |
48 try { | 51 try { |
49 return currentMirrorSystem().findLibrary(const Symbol('dart.io')); | 52 return currentMirrorSystem().findLibrary(const Symbol('dart.io')); |
50 } catch (_) { | 53 } catch (_) { |
51 // TODO(nweiz): narrow the catch clause when issue 18532 is fixed. | 54 // TODO(nweiz): narrow the catch clause when issue 18532 is fixed. |
52 return null; | 55 return null; |
53 } | 56 } |
54 } | 57 } |
OLD | NEW |