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

Unified Diff: pkg/http/lib/http.dart

Issue 65583004: Add utility methods for sending non-form data in pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http/lib/src/base_client.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/lib/http.dart
diff --git a/pkg/http/lib/http.dart b/pkg/http/lib/http.dart
index 752a53b4354352f49146ed7aa9366684e6cd2be5..2b76f8d0a7c6b70f5b1c99fce20b4af43a146e85 100644
--- a/pkg/http/lib/http.dart
+++ b/pkg/http/lib/http.dart
@@ -23,7 +23,7 @@
/// import 'package:http/http.dart' as http;
///
/// var url = "http://example.com/whatsit/create";
-/// http.post(url, fields: {"name": "doodle", "color": "blue"})
+/// http.post(url, body: {"name": "doodle", "color": "blue"})
/// .then((response) {
/// print("Response status: ${response.statusCode}");
/// print("Response body: ${response.body}");
@@ -38,7 +38,7 @@
/// var client = new http.Client();
/// client.post(
/// "http://example.com/whatsit/create",
-/// fields: {"name": "doodle", "color": "blue"})
+/// body: {"name": "doodle", "color": "blue"})
/// .then((response) => client.get(response.bodyFields['uri']))
/// .then((response) => print(response.body))
/// .whenComplete(client.close);
@@ -68,6 +68,7 @@
library http;
import 'dart:async';
+import 'dart:convert';
import 'dart:typed_data';
import 'src/client.dart';
@@ -107,35 +108,53 @@ Future<Response> head(url, {Map<String, String> headers}) =>
Future<Response> get(url, {Map<String, String> headers}) =>
_withClient((client) => client.get(url, headers: headers));
-/// Sends an HTTP POST request with the given headers and fields to the given
-/// URL, which an be a [Uri] or a [String]. If any fields are specified, the
-/// content-type is automatically set to `"application/x-www-form-urlencoded"`.
+/// Sends an HTTP POST request with the given headers and body to the given URL,
+/// which can be a [Uri] or a [String].
///
-/// This automatically initializes a new [Client] and closes that client once
-/// the request is complete. If you're planning on making multiple requests to
-/// the same server, you should use a single [Client] for all of those requests.
+/// [body] sets the body of the request. It can be a [String], a [List<int>] or
+/// a [Map<String, String>]. If it's a String, it's encoded using [encoding] and
+/// used as the body of the request. The content-type of the request will
+/// default to "text/plain".
+///
+/// If [body] is a List, it's used as a list of bytes for the body of the
+/// request.
+///
+/// If [body] is a Map, it's encoded as form fields using [encoding]. The
+/// content-type of the request will be set to
+/// `"application/x-www-form-urlencoded"`; this cannot be overridden.
+///
+/// [encoding] defaults to [UTF8].
///
/// For more fine-grained control over the request, use [Request] or
/// [StreamedRequest] instead.
-Future<Response> post(url,
- {Map<String, String> headers,
- Map<String, String> fields}) =>
- _withClient((client) => client.post(url, headers: headers, fields: fields));
+Future<Response> post(url, {Map<String, String> headers, body,
+ Encoding encoding}) =>
+ _withClient((client) => client.post(url,
+ headers: headers, body: body, encoding: encoding));
-/// Sends an HTTP POST request with the given headers and fields to the given
-/// URL, which can be a [Uri] or a [String]. If any fields are specified, the
-/// content-type is automatically set to `"application/x-www-form-urlencoded"`.
+/// Sends an HTTP PUT request with the given headers and body to the given URL,
+/// which can be a [Uri] or a [String].
///
-/// This automatically initializes a new [Client] and closes that client once
-/// the request is complete. If you're planning on making multiple requests to
-/// the same server, you should use a single [Client] for all of those requests.
+/// [body] sets the body of the request. It can be a [String], a [List<int>] or
+/// a [Map<String, String>]. If it's a String, it's encoded using [encoding] and
+/// used as the body of the request. The content-type of the request will
+/// default to "text/plain".
+///
+/// If [body] is a List, it's used as a list of bytes for the body of the
+/// request.
+///
+/// If [body] is a Map, it's encoded as form fields using [encoding]. The
+/// content-type of the request will be set to
+/// `"application/x-www-form-urlencoded"`; this cannot be overridden.
+///
+/// [encoding] defaults to [UTF8].
///
/// For more fine-grained control over the request, use [Request] or
/// [StreamedRequest] instead.
-Future<Response> put(url,
- {Map<String, String> headers,
- Map<String, String> fields}) =>
- _withClient((client) => client.put(url, headers: headers, fields: fields));
+Future<Response> put(url, {Map<String, String> headers, body,
+ Encoding encoding}) =>
+ _withClient((client) => client.put(url,
+ headers: headers, body: body, encoding: encoding));
/// Sends an HTTP DELETE request with the given headers to the given URL, which
/// can be a [Uri] or a [String].
« 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