Chromium Code Reviews| 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; |
| } |