Skip to content

Commit

Permalink
Removed uses of Chain.track
Browse files Browse the repository at this point in the history
R=nweiz@google.com

Review URL: https://codereview.chromium.org//1306723008 .
  • Loading branch information
kevmoo committed Aug 28, 2015
1 parent 6619d62 commit 8ecdfac
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.11.3+2

* Require Dart SDK >= 1.9.0

* Eliminate many uses of `Chain.track` from the `stack_trace` package.

## 0.11.3+1

* Support `http_parser` 1.0.0.
Expand Down
38 changes: 18 additions & 20 deletions lib/src/base_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'exception.dart';
import 'request.dart';
import 'response.dart';
import 'streamed_response.dart';
import 'utils.dart';

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

/// Sends a non-streaming [Request] and returns a non-streaming [Response].
Future<Response> _sendUnstreamed(String method, url,
Map<String, String> headers, [body, Encoding encoding]) {
return syncFuture(() {
if (url is String) url = Uri.parse(url);
var request = new Request(method, url);

if (headers != null) request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding;
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body;
} else if (body is Map) {
request.bodyFields = body;
} else {
throw new ArgumentError('Invalid request body "$body".');
}
Map<String, String> headers, [body, Encoding encoding]) async {

if (url is String) url = Uri.parse(url);
var request = new Request(method, url);

if (headers != null) request.headers.addAll(headers);
if (encoding != null) request.encoding = encoding;
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body;
} else if (body is Map) {
request.bodyFields = body;
} else {
throw new ArgumentError('Invalid request body "$body".');
}
}

return send(request);
}).then(Response.fromStream);
return Response.fromStream(await send(request));
}

/// Throws an error if [response] is not successful.
Expand Down
6 changes: 2 additions & 4 deletions lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ library io_client;

import 'dart:async';

import 'package:stack_trace/stack_trace.dart';

import 'base_client.dart';
import 'base_request.dart';
import 'exception.dart';
Expand Down Expand Up @@ -41,7 +39,7 @@ class IOClient extends BaseClient {
Future<StreamedResponse> send(BaseRequest request) {
var stream = request.finalize();

return Chain.track(_inner.openUrl(request.method, request.url))
return _inner.openUrl(request.method, request.url)
.then((ioRequest) {
var contentLength = request.contentLength == null ?
-1 : request.contentLength;
Expand All @@ -53,7 +51,7 @@ class IOClient extends BaseClient {
request.headers.forEach((name, value) {
ioRequest.headers.set(name, value);
});
return Chain.track(stream.pipe(ioRequest));
return stream.pipe(ioRequest);
}).then((response) {
var headers = {};
response.headers.forEach((key, values) {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/multipart_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:convert';

import 'package:http_parser/http_parser.dart';
import 'package:path/path.dart' as path;
import 'package:stack_trace/stack_trace.dart';

import 'byte_stream.dart';
import 'io.dart' as io;
Expand Down Expand Up @@ -93,8 +92,8 @@ class MultipartFile {
io.assertSupported("MultipartFile.fromPath");
if (filename == null) filename = path.basename(filePath);
var file = io.newFile(filePath);
return Chain.track(file.length()).then((length) {
var stream = new ByteStream(Chain.track(file.openRead()));
return file.length().then((length) {
var stream = new ByteStream(file.openRead());
return new MultipartFile(field, stream, length,
filename: filename,
contentType: contentType);
Expand Down
5 changes: 0 additions & 5 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:typed_data';

import 'package:stack_trace/stack_trace.dart';

import 'byte_stream.dart';

/// Converts a URL query string (or `application/x-www-form-urlencoded` body)
Expand Down Expand Up @@ -196,6 +194,3 @@ class Pair<E, F> {
void chainToCompleter(Future future, Completer completer) {
future.then(completer.complete, onError: completer.completeError);
}

/// Like [Future.sync], but wraps the Future in [Chain.track] as well.
Future syncFuture(callback()) => Chain.track(new Future.sync(callback));
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: http
version: 0.11.3+1
version: 0.11.3+2
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/http
description: A composable, Future-based API for making HTTP requests.
Expand All @@ -10,4 +10,4 @@ dependencies:
dev_dependencies:
unittest: ">=0.9.0 <0.12.0"
environment:
sdk: ">=1.1.0 <2.0.0"
sdk: ">=1.9.0 <2.0.0"

0 comments on commit 8ecdfac

Please sign in to comment.