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

Unified Diff: runtime/bin/http_impl.dart

Issue 9625008: Add support for using an URL for establishing HTTP connections (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
Index: runtime/bin/http_impl.dart
diff --git a/runtime/bin/http_impl.dart b/runtime/bin/http_impl.dart
index 9a3d9df04ae621bf7701a7dff12c689b6ee7c84a..91e528380aabeb5f495a01be8186b2de5e04804e 100644
--- a/runtime/bin/http_impl.dart
+++ b/runtime/bin/http_impl.dart
@@ -1056,14 +1056,39 @@ class _HttpClient implements HttpClient {
return _prepareHttpClientConnection(host, port, method, path);
}
+ HttpClientConnection openUrl(String method, Uri url) {
+ if (url.scheme != "http") {
+ throw new HttpException("Unsupported URL scheme ${url.scheme}");
+ }
+ if (url.userInfo != "") {
+ throw new HttpException("Unsupported user info in URL");
Mads Ager (google) 2012/03/08 08:02:52 Interpolate the userInfo?
Søren Gjesse 2012/03/08 08:30:04 Done.
+ }
+ int port = url.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : url.port;
+ String path;
Mads Ager (google) 2012/03/08 08:02:52 After the sanity checks, could you just use url.to
Søren Gjesse 2012/03/08 08:30:04 Unfortunately not, at that will add the prefix "ht
+ if (url.query != "") {
+ if (url.fragment != "") {
+ path = "${url.path}?${url.query}#${url.fragment}";
+ } else {
+ path = "${url.path}?${url.query}";
+ }
+ } else {
+ path = url.path;
+ }
+ return open(method, url.domain, port, path);
+ }
+
HttpClientConnection get(String host, int port, String path) {
return open("GET", host, port, path);
}
+ HttpClientConnection getUrl(Uri url) => openUrl("GET", url);
+
HttpClientConnection post(String host, int port, String path) {
return open("POST", host, port, path);
}
+ HttpClientConnection postUrl(Uri url) => openUrl("POST", url);
+
void shutdown() {
_openSockets.forEach((String key, Queue<_SocketConnection> connections) {
while (!connections.isEmpty()) {

Powered by Google App Engine
This is Rietveld 408576698