OLD | NEW |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 request.headers.forEach((name, value) { | 49 request.headers.forEach((name, value) { |
50 underlyingRequest.headers.set(name, value); | 50 underlyingRequest.headers.set(name, value); |
51 }); | 51 }); |
52 | 52 |
53 chainToCompleter( | 53 chainToCompleter( |
54 stream.pipe(wrapOutputStream(underlyingRequest.outputStream)), | 54 stream.pipe(wrapOutputStream(underlyingRequest.outputStream)), |
55 pipeCompleter); | 55 pipeCompleter); |
56 }; | 56 }; |
57 | 57 |
58 connection.onResponse = (response) { | 58 connection.onResponse = (response) { |
59 var headers = <String>{}; | 59 var headers = <String, String>{}; |
60 response.headers.forEach((key, value) => headers[key] = value); | 60 response.headers.forEach((key, value) => headers[key] = value); |
61 | 61 |
62 if (completed) return; | 62 if (completed) return; |
63 | 63 |
64 completed = true; | 64 completed = true; |
65 completer.complete(new StreamedResponse( | 65 completer.complete(new StreamedResponse( |
66 wrapInputStream(response.inputStream), | 66 wrapInputStream(response.inputStream), |
67 response.statusCode, | 67 response.statusCode, |
68 response.contentLength, | 68 response.contentLength, |
69 request: request, | 69 request: request, |
70 headers: headers, | 70 headers: headers, |
71 isRedirect: response.isRedirect, | 71 isRedirect: response.isRedirect, |
72 persistentConnection: response.persistentConnection, | 72 persistentConnection: response.persistentConnection, |
73 reasonPhrase: response.reasonPhrase)); | 73 reasonPhrase: response.reasonPhrase)); |
74 }; | 74 }; |
75 | 75 |
76 return Future.wait([ | 76 return Future.wait([ |
77 completer.future, | 77 completer.future, |
78 pipeCompleter.future | 78 pipeCompleter.future |
79 ]).then((values) => values.first); | 79 ]).then((values) => values.first); |
80 } | 80 } |
81 | 81 |
82 /// Closes the client. This terminates all active connections. If a client | 82 /// Closes the client. This terminates all active connections. If a client |
83 /// remains unclosed, the Dart process may not terminate. | 83 /// remains unclosed, the Dart process may not terminate. |
84 void close() { | 84 void close() { |
85 if (_inner != null) _inner.shutdown(force: true); | 85 if (_inner != null) _inner.shutdown(force: true); |
86 _inner = null; | 86 _inner = null; |
87 } | 87 } |
88 } | 88 } |
OLD | NEW |