Skip to content

Commit 8ecdfac

Browse files
committed
Removed uses of Chain.track
[email protected] Review URL: https://codereview.chromium.org//1306723008 .
1 parent 6619d62 commit 8ecdfac

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.11.3+2
2+
3+
* Require Dart SDK >= 1.9.0
4+
5+
* Eliminate many uses of `Chain.track` from the `stack_trace` package.
6+
17
## 0.11.3+1
28

39
* Support `http_parser` 1.0.0.

lib/src/base_client.dart

+18-20
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'exception.dart';
1414
import 'request.dart';
1515
import 'response.dart';
1616
import 'streamed_response.dart';
17-
import 'utils.dart';
1817

1918
/// The abstract base class for an HTTP client. This is a mixin-style class;
2019
/// subclasses only need to implement [send] and maybe [close], and then they
@@ -150,27 +149,26 @@ abstract class BaseClient implements Client {
150149

151150
/// Sends a non-streaming [Request] and returns a non-streaming [Response].
152151
Future<Response> _sendUnstreamed(String method, url,
153-
Map<String, String> headers, [body, Encoding encoding]) {
154-
return syncFuture(() {
155-
if (url is String) url = Uri.parse(url);
156-
var request = new Request(method, url);
157-
158-
if (headers != null) request.headers.addAll(headers);
159-
if (encoding != null) request.encoding = encoding;
160-
if (body != null) {
161-
if (body is String) {
162-
request.body = body;
163-
} else if (body is List) {
164-
request.bodyBytes = body;
165-
} else if (body is Map) {
166-
request.bodyFields = body;
167-
} else {
168-
throw new ArgumentError('Invalid request body "$body".');
169-
}
152+
Map<String, String> headers, [body, Encoding encoding]) async {
153+
154+
if (url is String) url = Uri.parse(url);
155+
var request = new Request(method, url);
156+
157+
if (headers != null) request.headers.addAll(headers);
158+
if (encoding != null) request.encoding = encoding;
159+
if (body != null) {
160+
if (body is String) {
161+
request.body = body;
162+
} else if (body is List) {
163+
request.bodyBytes = body;
164+
} else if (body is Map) {
165+
request.bodyFields = body;
166+
} else {
167+
throw new ArgumentError('Invalid request body "$body".');
170168
}
169+
}
171170

172-
return send(request);
173-
}).then(Response.fromStream);
171+
return Response.fromStream(await send(request));
174172
}
175173

176174
/// Throws an error if [response] is not successful.

lib/src/io_client.dart

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ library io_client;
66

77
import 'dart:async';
88

9-
import 'package:stack_trace/stack_trace.dart';
10-
119
import 'base_client.dart';
1210
import 'base_request.dart';
1311
import 'exception.dart';
@@ -41,7 +39,7 @@ class IOClient extends BaseClient {
4139
Future<StreamedResponse> send(BaseRequest request) {
4240
var stream = request.finalize();
4341

44-
return Chain.track(_inner.openUrl(request.method, request.url))
42+
return _inner.openUrl(request.method, request.url)
4543
.then((ioRequest) {
4644
var contentLength = request.contentLength == null ?
4745
-1 : request.contentLength;
@@ -53,7 +51,7 @@ class IOClient extends BaseClient {
5351
request.headers.forEach((name, value) {
5452
ioRequest.headers.set(name, value);
5553
});
56-
return Chain.track(stream.pipe(ioRequest));
54+
return stream.pipe(ioRequest);
5755
}).then((response) {
5856
var headers = {};
5957
response.headers.forEach((key, values) {

lib/src/multipart_file.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'dart:convert';
99

1010
import 'package:http_parser/http_parser.dart';
1111
import 'package:path/path.dart' as path;
12-
import 'package:stack_trace/stack_trace.dart';
1312

1413
import 'byte_stream.dart';
1514
import 'io.dart' as io;
@@ -93,8 +92,8 @@ class MultipartFile {
9392
io.assertSupported("MultipartFile.fromPath");
9493
if (filename == null) filename = path.basename(filePath);
9594
var file = io.newFile(filePath);
96-
return Chain.track(file.length()).then((length) {
97-
var stream = new ByteStream(Chain.track(file.openRead()));
95+
return file.length().then((length) {
96+
var stream = new ByteStream(file.openRead());
9897
return new MultipartFile(field, stream, length,
9998
filename: filename,
10099
contentType: contentType);

lib/src/utils.dart

-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'dart:async';
88
import 'dart:convert';
99
import 'dart:typed_data';
1010

11-
import 'package:stack_trace/stack_trace.dart';
12-
1311
import 'byte_stream.dart';
1412

1513
/// Converts a URL query string (or `application/x-www-form-urlencoded` body)
@@ -196,6 +194,3 @@ class Pair<E, F> {
196194
void chainToCompleter(Future future, Completer completer) {
197195
future.then(completer.complete, onError: completer.completeError);
198196
}
199-
200-
/// Like [Future.sync], but wraps the Future in [Chain.track] as well.
201-
Future syncFuture(callback()) => Chain.track(new Future.sync(callback));

pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: http
2-
version: 0.11.3+1
2+
version: 0.11.3+2
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.
@@ -10,4 +10,4 @@ dependencies:
1010
dev_dependencies:
1111
unittest: ">=0.9.0 <0.12.0"
1212
environment:
13-
sdk: ">=1.1.0 <2.0.0"
13+
sdk: ">=1.9.0 <2.0.0"

0 commit comments

Comments
 (0)