Skip to content

Commit 5940bb2

Browse files
authored
Stop using dart:mirrors. (#55)
1 parent 3ae6d4b commit 5940bb2

File tree

7 files changed

+17
-88
lines changed

7 files changed

+17
-88
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.11.3+10
2+
3+
* Stop using `dart:mirrors`.
4+
15
## 0.11.3+9
26

37
* Remove an extra newline in multipart chunks.

lib/browser_client.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import 'src/exception.dart';
1515
import 'src/streamed_response.dart';
1616

1717
// TODO(nweiz): Move this under src/, re-export from lib/http.dart, and use this
18-
// automatically from [new Client] once we can create an HttpRequest using
19-
// mirrors on dart2js (issue 18541) and dart2js doesn't crash on pkg/collection
20-
// (issue 18535).
18+
// automatically from [new Client] once sdk#24581 is fixed.
2119

2220
/// A `dart:html`-based HTTP client that runs in the browser and is backed by
2321
/// XMLHttpRequests.

lib/src/client.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:typed_data';
88

99
import 'base_client.dart';
1010
import 'base_request.dart';
11-
import 'io.dart' as io;
1211
import 'io_client.dart';
1312
import 'response.dart';
1413
import 'streamed_response.dart';
@@ -28,10 +27,7 @@ abstract class Client {
2827
/// Currently this will create an [IOClient] if `dart:io` is available and
2928
/// throw an [UnsupportedError] otherwise. In the future, it will create a
3029
/// [BrowserClient] if `dart:html` is available.
31-
factory Client() {
32-
io.assertSupported("IOClient");
33-
return new IOClient();
34-
}
30+
factory Client() => new IOClient();
3531

3632
/// Sends an HTTP HEAD request with the given headers to the given URL, which
3733
/// can be a [Uri] or a [String].

lib/src/io.dart

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/src/io_client.dart

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,24 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:async/async.dart';
89

910
import 'base_client.dart';
1011
import 'base_request.dart';
1112
import 'exception.dart';
12-
import 'io.dart' as io;
1313
import 'streamed_response.dart';
1414

1515
/// A `dart:io`-based HTTP client.
1616
///
1717
/// This is the default client when running on the command line.
1818
class 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
}

lib/src/multipart_file.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import 'dart:async';
66
import 'dart:convert';
7+
import 'dart:io';
78

89
import 'package:async/async.dart';
910
import 'package:http_parser/http_parser.dart';
1011
import 'package:path/path.dart' as path;
1112

1213
import 'byte_stream.dart';
13-
import 'io.dart' as io;
1414
import 'utils.dart';
1515

1616
/// A file to be uploaded as part of a [MultipartRequest]. This doesn't need to
@@ -85,12 +85,12 @@ class MultipartFile {
8585
/// defaults to `application/octet-stream`, but in the future may be inferred
8686
/// from [filename].
8787
///
88-
/// This can only be used in an environment that supports "dart:io".
88+
/// Throws an [UnsupportedError] if `dart:io` isn't supported in this
89+
/// environment.
8990
static Future<MultipartFile> fromPath(String field, String filePath,
9091
{String filename, MediaType contentType}) async {
91-
io.assertSupported("MultipartFile.fromPath");
9292
if (filename == null) filename = path.basename(filePath);
93-
var file = io.newFile(filePath);
93+
var file = new File(filePath);
9494
var length = await file.length();
9595
var stream = new ByteStream(DelegatingStream.typed(file.openRead()));
9696
return new MultipartFile(field, stream, length,

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http
2-
version: 0.11.3+9
2+
version: 0.11.3+10
33
author: "Dart Team <[email protected]>"
44
homepage: https://github.com/dart-lang/http
55
description: A composable, Future-based API for making HTTP requests.
@@ -12,4 +12,4 @@ dependencies:
1212
dev_dependencies:
1313
unittest: ">=0.9.0 <0.12.0"
1414
environment:
15-
sdk: ">=1.9.0 <2.0.0"
15+
sdk: ">=1.22.0 <2.0.0"

0 commit comments

Comments
 (0)