Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: pkg/http/lib/src/utils.dart

Issue 11293289: Make the HTTP MockClient work with GET requests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/http/test/mock_client_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 utils; 5 library utils;
6 6
7 import 'dart:crypto'; 7 import 'dart:crypto';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import 'dart:scalarlist'; 10 import 'dart:scalarlist';
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (input is Uint8List) return input; 126 if (input is Uint8List) return input;
127 if (input is ByteArrayViewable) input = input.asByteArray(); 127 if (input is ByteArrayViewable) input = input.asByteArray();
128 if (input is ByteArray) return new Uint8List.view(input); 128 if (input is ByteArray) return new Uint8List.view(input);
129 var output = new Uint8List(input.length); 129 var output = new Uint8List(input.length);
130 output.setRange(0, input.length, input); 130 output.setRange(0, input.length, input);
131 return output; 131 return output;
132 } 132 }
133 133
134 /// Buffers all input from an InputStream and returns it as a future. 134 /// Buffers all input from an InputStream and returns it as a future.
135 Future<List<int>> consumeInputStream(InputStream stream) { 135 Future<List<int>> consumeInputStream(InputStream stream) {
136 if (stream.closed) return new Future<List<int>>.immediate(<int>[]);
137
136 var completer = new Completer<List<int>>(); 138 var completer = new Completer<List<int>>();
137 /// TODO(nweiz): use BufferList when issue 6409 is fixed 139 /// TODO(nweiz): use BufferList when issue 6409 is fixed
138 var buffer = <int>[]; 140 var buffer = <int>[];
139 stream.onClosed = () => completer.complete(buffer); 141 stream.onClosed = () => completer.complete(buffer);
140 stream.onData = () => buffer.addAll(stream.read()); 142 stream.onData = () => buffer.addAll(stream.read());
141 stream.onError = completer.completeException; 143 stream.onError = completer.completeException;
142 return completer.future; 144 return completer.future;
143 } 145 }
144 146
145 /// Takes all input from [source] and writes it to [sink], then closes [sink]. 147 /// Takes all input from [source] and writes it to [sink], then closes [sink].
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 201
200 /// Configures [future] so that its result (success or exception) is passed on 202 /// Configures [future] so that its result (success or exception) is passed on
201 /// to [completer]. 203 /// to [completer].
202 void chainToCompleter(Future future, Completer completer) { 204 void chainToCompleter(Future future, Completer completer) {
203 future.handleException((e) { 205 future.handleException((e) {
204 completer.completeException(e); 206 completer.completeException(e);
205 return true; 207 return true;
206 }); 208 });
207 future.then(completer.complete); 209 future.then(completer.complete);
208 } 210 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http/test/mock_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698