| 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 /// The easiest way to use this library is via the top-level functions. They | 7 /// The easiest way to use this library is via the top-level functions. They |
| 8 /// allow you to make individual HTTP requests with minimal hassle: | 8 /// allow you to make individual HTTP requests with minimal hassle: |
| 9 /// | 9 /// |
| 10 /// import 'package:http/http.dart' as http; | 10 /// import 'package:http/http.dart' as http; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 /// final String userAgent; | 43 /// final String userAgent; |
| 44 /// final http.Client _inner; | 44 /// final http.Client _inner; |
| 45 /// | 45 /// |
| 46 /// UserAgentClient(this.userAgent, this._inner); | 46 /// UserAgentClient(this.userAgent, this._inner); |
| 47 /// | 47 /// |
| 48 /// Future<StreamedResponse> send(BaseRequest request) { | 48 /// Future<StreamedResponse> send(BaseRequest request) { |
| 49 /// request.headers[HttpHeaders.USER_AGENT] = userAgent; | 49 /// request.headers[HttpHeaders.USER_AGENT] = userAgent; |
| 50 /// return _inner.send(request); | 50 /// return _inner.send(request); |
| 51 /// } | 51 /// } |
| 52 /// } | 52 /// } |
| 53 | |
| 54 library http; | 53 library http; |
| 55 | 54 |
| 56 import 'dart:async'; | 55 import 'dart:async'; |
| 57 import 'dart:typeddata'; | 56 import 'dart:typeddata'; |
| 58 import 'dart:uri'; | 57 import 'dart:uri'; |
| 59 | 58 |
| 60 import 'src/client.dart'; | 59 import 'src/client.dart'; |
| 61 import 'src/response.dart'; | 60 import 'src/response.dart'; |
| 62 | 61 |
| 63 export 'src/base_client.dart'; | 62 export 'src/base_client.dart'; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 /// For more fine-grained control over the request and response, use [Request] | 164 /// For more fine-grained control over the request and response, use [Request] |
| 166 /// instead. | 165 /// instead. |
| 167 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => | 166 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => |
| 168 _withClient((client) => client.readBytes(url, headers: headers)); | 167 _withClient((client) => client.readBytes(url, headers: headers)); |
| 169 | 168 |
| 170 Future _withClient(Future fn(Client)) { | 169 Future _withClient(Future fn(Client)) { |
| 171 var client = new Client(); | 170 var client = new Client(); |
| 172 var future = fn(client); | 171 var future = fn(client); |
| 173 return future.whenComplete(client.close); | 172 return future.whenComplete(client.close); |
| 174 } | 173 } |
| OLD | NEW |