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

Unified Diff: sdk/lib/io/http_impl.dart

Issue 11299210: Add support for https scheme in dart:io HttpClient. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 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 | « sdk/lib/io/http.dart ('k') | tests/standalone/io/https_client_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index c78348120f47f71707b21bc1294a9265091b81a1..201c12454b2ac1498a9a67bc0799a1d9d8d0dbd4 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -1704,7 +1704,7 @@ class _HttpClient implements HttpClient {
HttpClientConnection _openUrl(String method,
Uri url,
[_HttpClientConnection connection]) {
- if (url.scheme != "http") {
+ if (url.scheme != "http" && url.scheme != "https") {
throw new HttpException("Unsupported URL scheme ${url.scheme}");
}
return _open(method, url, connection);
@@ -1769,7 +1769,8 @@ class _HttpClient implements HttpClient {
int port,
_ProxyConfiguration proxyConfiguration,
int proxyIndex,
- bool reusedConnection) {
+ bool reusedConnection,
+ bool secure) {
void _connectionOpened(_SocketConnection socketConn,
_HttpClientConnection connection,
@@ -1821,8 +1822,15 @@ class _HttpClient implements HttpClient {
// otherwise create a new one.
String key = _connectionKey(connectHost, connectPort);
Queue socketConnections = _openSockets[key];
+ // Remove active connections that are of the wrong type (HTTP or HTTPS).
+ while (socketConnections != null &&
+ !socketConnections.isEmpty &&
+ secure != (socketConnections.first._socket is SecureSocket)) {
+ socketConnection.removeFirst()._close();
+ }
if (socketConnections == null || socketConnections.isEmpty) {
- Socket socket = new Socket(connectHost, connectPort);
+ Socket socket = secure ? new SecureSocket(connectHost, connectPort) :
+ new Socket(connectHost, connectPort);
// Until the connection is established handle connection errors
// here as the HttpClientConnection object is not yet associated
// with the socket.
@@ -1845,7 +1853,7 @@ class _HttpClient implements HttpClient {
// the connected socket.
socket.onError = null;
_SocketConnection socketConn =
- new _SocketConnection(connectHost, connectPort, socket);
+ new _SocketConnection(connectHost, connectPort, socket);
_activeSockets.add(socketConn);
_connectionOpened(socketConn, connection, !proxy.isDirect);
};
@@ -1861,10 +1869,17 @@ class _HttpClient implements HttpClient {
}
}
+ // Find out if we want a secure socket.
+ bool secure = (url.scheme == "https");
Mads Ager (google) 2012/11/29 08:29:12 I would remove the extra parenthesis here.
+
// Find the TCP host and port.
String host = url.domain;
- int port = url.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : url.port;
-
+ int port = url.port;
+ if (port == 0) {
+ port = secure ?
+ HttpClient.DEFAULT_HTTPS_PORT :
+ HttpClient.DEFAULT_HTTP_PORT;
+ }
// Create a new connection object if we are not re-using an existing one.
var reusedConnection = false;
if (connection == null) {
@@ -1883,7 +1898,12 @@ class _HttpClient implements HttpClient {
}
// Establish the connection starting with the first proxy configured.
- _establishConnection(host, port, proxyConfiguration, 0, reusedConnection);
+ _establishConnection(host,
+ port,
+ proxyConfiguration,
+ 0,
+ reusedConnection,
+ secure);
return connection;
}
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/https_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698