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

Unified Diff: dart/pkg/http_base/lib/http_base_io.dart

Issue 445933004: Add implementations for Headers, Request, Response and dart:io/dart:html clients to http_base (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/pkg/http_base/lib/http_base_html.dart ('k') | dart/pkg/http_base/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/pkg/http_base/lib/http_base_io.dart
diff --git a/dart/pkg/http_base/lib/http_base_io.dart b/dart/pkg/http_base/lib/http_base_io.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f33383d5eda15c07de881a5794925077405d8774
--- /dev/null
+++ b/dart/pkg/http_base/lib/http_base_io.dart
@@ -0,0 +1,38 @@
+library http_base.http_base_io;
+
+import 'dart:io' as io;
+import 'dart:async';
+
+import 'http_base.dart';
+export 'http_base.dart';
+
+/// An implementation for [RequestHandler]. It uses dart:io to make http
+/// requests.
+class Client {
+ // TODO: Should we provide a mechanism to close (forcefully or not) [_client]?
+ final io.HttpClient _client = new io.HttpClient();
+
+ Future<Response> call(Request request) {
+ return _client.openUrl(request.method, request.url).then((ioRequest) {
+ // TODO: Special case Cookie/Set-Cookie here!
+
+ for (var name in request.headers.names) {
+ ioRequest.headers.set(name, request.headers[name]);
+ }
+
+ var stream = request.read();
+ return ioRequest.addStream(stream).then((_) {
+ return ioRequest.close();
+ });
+ }).then((io.HttpClientResponse ioResponse) {
+ var headerMap = {};
+ ioResponse.headers.forEach((name, values) {
+ headerMap[name] = values;
+ });
+ var headers = new HeadersImpl(headerMap);
+
+ return new ResponseImpl(
+ ioResponse.statusCode, headers: headers, body: ioResponse);
+ });
+ }
+}
« no previous file with comments | « dart/pkg/http_base/lib/http_base_html.dart ('k') | dart/pkg/http_base/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698