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

Side by Side Diff: pkg/http/lib/http.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 | « no previous file | pkg/http/lib/src/base_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) 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 10 matching lines...) Expand all
21 /// If you're making multiple requests to the same server, you can keep open a 21 /// If you're making multiple requests to the same server, you can keep open a
22 /// persistent connection by using a [Client] rather than making one-off 22 /// persistent connection by using a [Client] rather than making one-off
23 /// requests. If you do this, make sure to close the client when you're done: 23 /// requests. If you do this, make sure to close the client when you're done:
24 /// 24 ///
25 /// var client = new http.Client(); 25 /// var client = new http.Client();
26 /// client.post( 26 /// client.post(
27 /// "http://example.com/whatsit/create", 27 /// "http://example.com/whatsit/create",
28 /// fields: {"name": "doodle", "color": "blue"}) 28 /// fields: {"name": "doodle", "color": "blue"})
29 /// .then((response) => client.get(response.bodyFields['uri'])) 29 /// .then((response) => client.get(response.bodyFields['uri']))
30 /// .then((response) => print(response.body)) 30 /// .then((response) => print(response.body))
31 /// .onComplete((_) => client.close()); 31 /// .whenComplete(client.close);
32 /// 32 ///
33 /// You can also exert more fine-grained control over your requests and 33 /// You can also exert more fine-grained control over your requests and
34 /// responses by creating [Request] or [StreamedRequest] objects yourself and 34 /// responses by creating [Request] or [StreamedRequest] objects yourself and
35 /// passing them to [Client.send]. 35 /// passing them to [Client.send].
36 /// 36 ///
37 /// This package is designed to be composable. This makes it easy for external 37 /// This package is designed to be composable. This makes it easy for external
38 /// libraries to work with one another to add behavior to it. Libraries wishing 38 /// libraries to work with one another to add behavior to it. Libraries wishing
39 /// to add behavior should create a subclass of [BaseClient] that wraps another 39 /// to add behavior should create a subclass of [BaseClient] that wraps another
40 /// [Client] and adds the desired behavior: 40 /// [Client] and adds the desired behavior:
41 /// 41 ///
(...skipping 14 matching lines...) Expand all
56 import 'dart:async'; 56 import 'dart:async';
57 import 'dart:scalarlist'; 57 import 'dart:scalarlist';
58 import 'dart:uri'; 58 import 'dart:uri';
59 59
60 import 'src/client.dart'; 60 import 'src/client.dart';
61 import 'src/response.dart'; 61 import 'src/response.dart';
62 62
63 export 'src/base_client.dart'; 63 export 'src/base_client.dart';
64 export 'src/base_request.dart'; 64 export 'src/base_request.dart';
65 export 'src/base_response.dart'; 65 export 'src/base_response.dart';
66 export 'src/byte_stream.dart';
66 export 'src/client.dart'; 67 export 'src/client.dart';
67 export 'src/multipart_file.dart'; 68 export 'src/multipart_file.dart';
68 export 'src/multipart_request.dart'; 69 export 'src/multipart_request.dart';
69 export 'src/request.dart'; 70 export 'src/request.dart';
70 export 'src/response.dart'; 71 export 'src/response.dart';
71 export 'src/streamed_request.dart'; 72 export 'src/streamed_request.dart';
72 export 'src/streamed_response.dart'; 73 export 'src/streamed_response.dart';
73 74
74 /// Sends an HTTP HEAD request with the given headers to the given URL, which 75 /// Sends an HTTP HEAD request with the given headers to the given URL, which
75 /// can be a [Uri] or a [String]. 76 /// can be a [Uri] or a [String].
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 /// the same server, you should use a single [Client] for all of those requests. 163 /// the same server, you should use a single [Client] for all of those requests.
163 /// 164 ///
164 /// For more fine-grained control over the request and response, use [Request] 165 /// For more fine-grained control over the request and response, use [Request]
165 /// instead. 166 /// instead.
166 Future<Uint8List> readBytes(url, {Map<String, String> headers}) => 167 Future<Uint8List> readBytes(url, {Map<String, String> headers}) =>
167 _withClient((client) => client.readBytes(url, headers: headers)); 168 _withClient((client) => client.readBytes(url, headers: headers));
168 169
169 Future _withClient(Future fn(Client)) { 170 Future _withClient(Future fn(Client)) {
170 var client = new Client(); 171 var client = new Client();
171 var future = fn(client); 172 var future = fn(client);
172 future.catchError((_) {}).then((_) => client.close()); 173 return future.whenComplete(client.close);
173 return future;
174 } 174 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http/lib/src/base_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698