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 /// | 6 /// |
7 /// ## Installing ## | 7 /// ## Installing ## |
8 /// | 8 /// |
9 /// Use [pub][] to install this package. Add the following to your | 9 /// Use [pub][] to install this package. Add the following to your |
10 /// `pubspec.yaml` file. | 10 /// `pubspec.yaml` file. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 /// Future<StreamedResponse> send(BaseRequest request) { | 61 /// Future<StreamedResponse> send(BaseRequest request) { |
62 /// request.headers[HttpHeaders.USER_AGENT] = userAgent; | 62 /// request.headers[HttpHeaders.USER_AGENT] = userAgent; |
63 /// return _inner.send(request); | 63 /// return _inner.send(request); |
64 /// } | 64 /// } |
65 /// } | 65 /// } |
66 /// | 66 /// |
67 /// [pub]: http://pub.dartlang.org | 67 /// [pub]: http://pub.dartlang.org |
68 library http; | 68 library http; |
69 | 69 |
70 import 'dart:async'; | 70 import 'dart:async'; |
71 import 'dart:typeddata'; | 71 import 'dart:typed_data'; |
72 import 'dart:uri'; | 72 import 'dart:uri'; |
73 | 73 |
74 import 'src/client.dart'; | 74 import 'src/client.dart'; |
75 import 'src/response.dart'; | 75 import 'src/response.dart'; |
76 | 76 |
77 export 'src/base_client.dart'; | 77 export 'src/base_client.dart'; |
78 export 'src/base_request.dart'; | 78 export 'src/base_request.dart'; |
79 export 'src/base_response.dart'; | 79 export 'src/base_response.dart'; |
80 export 'src/byte_stream.dart'; | 80 export 'src/byte_stream.dart'; |
81 export 'src/client.dart'; | 81 export 'src/client.dart'; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 /// For more fine-grained control over the request and response, use [Request] | 179 /// For more fine-grained control over the request and response, use [Request] |
180 /// instead. | 180 /// instead. |
181 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => | 181 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => |
182 _withClient((client) => client.readBytes(url, headers: headers)); | 182 _withClient((client) => client.readBytes(url, headers: headers)); |
183 | 183 |
184 Future _withClient(Future fn(Client)) { | 184 Future _withClient(Future fn(Client)) { |
185 var client = new Client(); | 185 var client = new Client(); |
186 var future = fn(client); | 186 var future = fn(client); |
187 return future.whenComplete(client.close); | 187 return future.whenComplete(client.close); |
188 } | 188 } |
OLD | NEW |