OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// A composable, [Future]-based library for making HTTP requests. | 5 /// A composable, [Future]-based library for making HTTP requests. |
6 library http; | |
7 | |
8 import 'dart:async'; | 6 import 'dart:async'; |
9 import 'dart:convert'; | 7 import 'dart:convert'; |
10 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
11 | 9 |
12 import 'src/client.dart'; | 10 import 'src/client.dart'; |
13 import 'src/response.dart'; | 11 import 'src/response.dart'; |
14 | 12 |
15 export 'src/base_client.dart'; | 13 export 'src/base_client.dart'; |
16 export 'src/base_request.dart'; | 14 export 'src/base_request.dart'; |
17 export 'src/base_response.dart'; | 15 export 'src/base_response.dart'; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 /// For more fine-grained control over the request and response, use [Request] | 159 /// For more fine-grained control over the request and response, use [Request] |
162 /// instead. | 160 /// instead. |
163 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => | 161 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => |
164 _withClient((client) => client.readBytes(url, headers: headers)); | 162 _withClient((client) => client.readBytes(url, headers: headers)); |
165 | 163 |
166 Future _withClient(Future fn(Client)) { | 164 Future _withClient(Future fn(Client)) { |
167 var client = new Client(); | 165 var client = new Client(); |
168 var future = fn(client); | 166 var future = fn(client); |
169 return future.whenComplete(client.close); | 167 return future.whenComplete(client.close); |
170 } | 168 } |
OLD | NEW |