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

Side by Side 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: Addressed rewiev comments from @ager 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpClientTest.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Utility class for encoding a string into UTF-8 byte stream. 5 // Utility class for encoding a string into UTF-8 byte stream.
6 class _UTF8Encoder { 6 class _UTF8Encoder {
7 static List<int> encodeString(String string) { 7 static List<int> encodeString(String string) {
8 int size = _encodingSize(string); 8 int size = _encodingSize(string);
9 ByteArray result = new ByteArray(size); 9 ByteArray result = new ByteArray(size);
10 _encodeString(string, result); 10 _encodeString(string, result);
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 _HttpClient() : _openSockets = new Map(), 1049 _HttpClient() : _openSockets = new Map(),
1050 _activeSockets = new Set(), 1050 _activeSockets = new Set(),
1051 _shutdown = false; 1051 _shutdown = false;
1052 1052
1053 HttpClientConnection open( 1053 HttpClientConnection open(
1054 String method, String host, int port, String path) { 1054 String method, String host, int port, String path) {
1055 if (_shutdown) throw new HttpException("HttpClient shutdown"); 1055 if (_shutdown) throw new HttpException("HttpClient shutdown");
1056 return _prepareHttpClientConnection(host, port, method, path); 1056 return _prepareHttpClientConnection(host, port, method, path);
1057 } 1057 }
1058 1058
1059 HttpClientConnection openUrl(String method, Uri url) {
1060 if (url.scheme != "http") {
1061 throw new HttpException("Unsupported URL scheme ${url.scheme}");
1062 }
1063 if (url.userInfo != "") {
1064 throw new HttpException("Unsupported user info ${url.userInfo}");
1065 }
1066 int port = url.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : url.port;
1067 String path;
1068 if (url.query != "") {
1069 if (url.fragment != "") {
1070 path = "${url.path}?${url.query}#${url.fragment}";
1071 } else {
1072 path = "${url.path}?${url.query}";
1073 }
1074 } else {
1075 path = url.path;
1076 }
1077 return open(method, url.domain, port, path);
1078 }
1079
1059 HttpClientConnection get(String host, int port, String path) { 1080 HttpClientConnection get(String host, int port, String path) {
1060 return open("GET", host, port, path); 1081 return open("GET", host, port, path);
1061 } 1082 }
1062 1083
1084 HttpClientConnection getUrl(Uri url) => openUrl("GET", url);
1085
1063 HttpClientConnection post(String host, int port, String path) { 1086 HttpClientConnection post(String host, int port, String path) {
1064 return open("POST", host, port, path); 1087 return open("POST", host, port, path);
1065 } 1088 }
1066 1089
1090 HttpClientConnection postUrl(Uri url) => openUrl("POST", url);
1091
1067 void shutdown() { 1092 void shutdown() {
1068 _openSockets.forEach((String key, Queue<_SocketConnection> connections) { 1093 _openSockets.forEach((String key, Queue<_SocketConnection> connections) {
1069 while (!connections.isEmpty()) { 1094 while (!connections.isEmpty()) {
1070 _SocketConnection socketConn = connections.removeFirst(); 1095 _SocketConnection socketConn = connections.removeFirst();
1071 socketConn._socket.close(); 1096 socketConn._socket.close();
1072 } 1097 }
1073 }); 1098 });
1074 _activeSockets.forEach((_SocketConnection socketConn) { 1099 _activeSockets.forEach((_SocketConnection socketConn) {
1075 socketConn._socket.close(); 1100 socketConn._socket.close();
1076 }); 1101 });
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 _onError = callback; 1207 _onError = callback;
1183 } 1208 }
1184 1209
1185 Function _onOpen; 1210 Function _onOpen;
1186 Function _onError; 1211 Function _onError;
1187 Map<String, Queue<_SocketConnection>> _openSockets; 1212 Map<String, Queue<_SocketConnection>> _openSockets;
1188 Set<_SocketConnection> _activeSockets; 1213 Set<_SocketConnection> _activeSockets;
1189 Timer _evictionTimer; 1214 Timer _evictionTimer;
1190 bool _shutdown; // Has this HTTP client been shutdown? 1215 bool _shutdown; // Has this HTTP client been shutdown?
1191 } 1216 }
OLDNEW
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpClientTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698