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

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

Issue 11825010: Update pkg/http to use the new async APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 11 months 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 | « pkg/http/lib/src/byte_stream.dart ('k') | pkg/http/lib/src/mock_client.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 io_client; 5 library io_client;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'base_client.dart'; 10 import 'base_client.dart';
(...skipping 24 matching lines...) Expand all
35 // onRequest or onResponse callbacks get passed to onError. If the 35 // onRequest or onResponse callbacks get passed to onError. If the
36 // completer has already fired, we want to re-throw those exceptions 36 // completer has already fired, we want to re-throw those exceptions
37 // to the top level so that they aren't silently ignored. 37 // to the top level so that they aren't silently ignored.
38 if (completed) throw e; 38 if (completed) throw e;
39 39
40 completed = true; 40 completed = true;
41 completer.completeError(e); 41 completer.completeError(e);
42 }); 42 });
43 }; 43 };
44 44
45 var pipeCompleter = new Completer();
45 connection.onRequest = (underlyingRequest) { 46 connection.onRequest = (underlyingRequest) {
46 underlyingRequest.contentLength = request.contentLength; 47 underlyingRequest.contentLength = request.contentLength;
47 underlyingRequest.persistentConnection = request.persistentConnection; 48 underlyingRequest.persistentConnection = request.persistentConnection;
48 request.headers.forEach((name, value) { 49 request.headers.forEach((name, value) {
49 underlyingRequest.headers.set(name, value); 50 underlyingRequest.headers.set(name, value);
50 }); 51 });
51 52
52 if (stream.closed) { 53 chainToCompleter(
53 underlyingRequest.outputStream.close(); 54 stream.pipe(wrapOutputStream(underlyingRequest.outputStream)),
54 } else { 55 pipeCompleter);
55 stream.pipe(underlyingRequest.outputStream);
56 }
57 }; 56 };
58 57
59 connection.onResponse = (response) { 58 connection.onResponse = (response) {
60 var headers = <String>{}; 59 var headers = <String>{};
61 response.headers.forEach((key, value) => headers[key] = value); 60 response.headers.forEach((key, value) => headers[key] = value);
62 61
63 if (completed) return; 62 if (completed) return;
64 63
65 completed = true; 64 completed = true;
66 completer.complete(new StreamedResponse( 65 completer.complete(new StreamedResponse(
67 response.inputStream, 66 wrapInputStream(response.inputStream),
68 response.statusCode, 67 response.statusCode,
69 response.contentLength, 68 response.contentLength,
70 request: request, 69 request: request,
71 headers: headers, 70 headers: headers,
72 isRedirect: response.isRedirect, 71 isRedirect: response.isRedirect,
73 persistentConnection: response.persistentConnection, 72 persistentConnection: response.persistentConnection,
74 reasonPhrase: response.reasonPhrase)); 73 reasonPhrase: response.reasonPhrase));
75 }; 74 };
76 75
77 return completer.future; 76 return pipeCompleter.future.then((_) => completer.future);
78 } 77 }
79 78
80 /// Closes the client. This terminates all active connections. If a client 79 /// Closes the client. This terminates all active connections. If a client
81 /// remains unclosed, the Dart process may not terminate. 80 /// remains unclosed, the Dart process may not terminate.
82 void close() { 81 void close() {
83 if (_inner != null) _inner.shutdown(force: true); 82 if (_inner != null) _inner.shutdown(force: true);
84 _inner = null; 83 _inner = null;
85 } 84 }
86 } 85 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/byte_stream.dart ('k') | pkg/http/lib/src/mock_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698