OLD | NEW |
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 // The close queue handles graceful closing of HTTP connections. When | 5 // The close queue handles graceful closing of HTTP connections. When |
6 // a connection is added to the queue it will enter a wait state | 6 // a connection is added to the queue it will enter a wait state |
7 // waiting for all data written and possibly socket shutdown from | 7 // waiting for all data written and possibly socket shutdown from |
8 // peer. | 8 // peer. |
9 class _CloseQueue { | 9 class _CloseQueue { |
10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); | 10 _CloseQueue() : _q = new Set<_HttpConnectionBase>(); |
(...skipping 1821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1832 Socket socket = secure ? new SecureSocket(connectHost, connectPort) : | 1832 Socket socket = secure ? new SecureSocket(connectHost, connectPort) : |
1833 new Socket(connectHost, connectPort); | 1833 new Socket(connectHost, connectPort); |
1834 // Until the connection is established handle connection errors | 1834 // Until the connection is established handle connection errors |
1835 // here as the HttpClientConnection object is not yet associated | 1835 // here as the HttpClientConnection object is not yet associated |
1836 // with the socket. | 1836 // with the socket. |
1837 socket.onError = (e) { | 1837 socket.onError = (e) { |
1838 proxyIndex++; | 1838 proxyIndex++; |
1839 if (proxyIndex < proxyConfiguration.proxies.length) { | 1839 if (proxyIndex < proxyConfiguration.proxies.length) { |
1840 // Try the next proxy in the list. | 1840 // Try the next proxy in the list. |
1841 _establishConnection( | 1841 _establishConnection( |
1842 host, port, proxyConfiguration, proxyIndex, false); | 1842 host, port, proxyConfiguration, proxyIndex, false, secure); |
1843 } else { | 1843 } else { |
1844 // Report the error through the HttpClientConnection object to | 1844 // Report the error through the HttpClientConnection object to |
1845 // the client. | 1845 // the client. |
1846 connection._onError(e); | 1846 connection._onError(e); |
1847 } | 1847 } |
1848 }; | 1848 }; |
1849 socket.onConnect = () { | 1849 socket.onConnect = () { |
1850 // When the connection is established, clear the error | 1850 // When the connection is established, clear the error |
1851 // callback as it will now be handled by the | 1851 // callback as it will now be handled by the |
1852 // HttpClientConnection object which will be associated with | 1852 // HttpClientConnection object which will be associated with |
(...skipping 10 matching lines...) Expand all Loading... |
1863 new Timer(0, (ignored) => | 1863 new Timer(0, (ignored) => |
1864 _connectionOpened(socketConn, connection, !proxy.isDirect)); | 1864 _connectionOpened(socketConn, connection, !proxy.isDirect)); |
1865 | 1865 |
1866 // Get rid of eviction timer if there are no more active connections. | 1866 // Get rid of eviction timer if there are no more active connections. |
1867 if (socketConnections.isEmpty) _openSockets.remove(key); | 1867 if (socketConnections.isEmpty) _openSockets.remove(key); |
1868 if (_openSockets.isEmpty) _cancelEvictionTimer(); | 1868 if (_openSockets.isEmpty) _cancelEvictionTimer(); |
1869 } | 1869 } |
1870 } | 1870 } |
1871 | 1871 |
1872 // Find out if we want a secure socket. | 1872 // Find out if we want a secure socket. |
1873 bool secure = (url.scheme == "https"); | 1873 bool is_secure = (url.scheme == "https"); |
1874 | 1874 |
1875 // Find the TCP host and port. | 1875 // Find the TCP host and port. |
1876 String host = url.domain; | 1876 String host = url.domain; |
1877 int port = url.port; | 1877 int port = url.port; |
1878 if (port == 0) { | 1878 if (port == 0) { |
1879 port = secure ? | 1879 port = is_secure ? |
1880 HttpClient.DEFAULT_HTTPS_PORT : | 1880 HttpClient.DEFAULT_HTTPS_PORT : |
1881 HttpClient.DEFAULT_HTTP_PORT; | 1881 HttpClient.DEFAULT_HTTP_PORT; |
1882 } | 1882 } |
1883 // Create a new connection object if we are not re-using an existing one. | 1883 // Create a new connection object if we are not re-using an existing one. |
1884 var reusedConnection = false; | 1884 var reusedConnection = false; |
1885 if (connection == null) { | 1885 if (connection == null) { |
1886 connection = new _HttpClientConnection(this); | 1886 connection = new _HttpClientConnection(this); |
1887 } else { | 1887 } else { |
1888 reusedConnection = true; | 1888 reusedConnection = true; |
1889 } | 1889 } |
1890 connection.onDetach = () => _activeSockets.remove(connection._socketConn); | 1890 connection.onDetach = () => _activeSockets.remove(connection._socketConn); |
1891 | 1891 |
1892 // Check to see if a proxy server should be used for this connection. | 1892 // Check to see if a proxy server should be used for this connection. |
1893 _ProxyConfiguration proxyConfiguration = const _ProxyConfiguration.direct(); | 1893 _ProxyConfiguration proxyConfiguration = const _ProxyConfiguration.direct(); |
1894 if (_findProxy != null) { | 1894 if (_findProxy != null) { |
1895 // TODO(sgjesse): Keep a map of these as normally only a few | 1895 // TODO(sgjesse): Keep a map of these as normally only a few |
1896 // configuration strings will be used. | 1896 // configuration strings will be used. |
1897 proxyConfiguration = new _ProxyConfiguration(_findProxy(url)); | 1897 proxyConfiguration = new _ProxyConfiguration(_findProxy(url)); |
1898 } | 1898 } |
1899 | 1899 |
1900 // Establish the connection starting with the first proxy configured. | 1900 // Establish the connection starting with the first proxy configured. |
1901 _establishConnection(host, | 1901 _establishConnection(host, |
1902 port, | 1902 port, |
1903 proxyConfiguration, | 1903 proxyConfiguration, |
1904 0, | 1904 0, |
1905 reusedConnection, | 1905 reusedConnection, |
1906 secure); | 1906 is_secure); |
1907 | 1907 |
1908 return connection; | 1908 return connection; |
1909 } | 1909 } |
1910 | 1910 |
1911 void _returnSocketConnection(_SocketConnection socketConn) { | 1911 void _returnSocketConnection(_SocketConnection socketConn) { |
1912 // If the HTTP client is being shutdown don't return the connection. | 1912 // If the HTTP client is being shutdown don't return the connection. |
1913 if (_shutdown) { | 1913 if (_shutdown) { |
1914 socketConn._close(); | 1914 socketConn._close(); |
1915 return; | 1915 return; |
1916 }; | 1916 }; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 | 2125 |
2126 | 2126 |
2127 class _RedirectInfo implements RedirectInfo { | 2127 class _RedirectInfo implements RedirectInfo { |
2128 const _RedirectInfo(int this.statusCode, | 2128 const _RedirectInfo(int this.statusCode, |
2129 String this.method, | 2129 String this.method, |
2130 Uri this.location); | 2130 Uri this.location); |
2131 final int statusCode; | 2131 final int statusCode; |
2132 final String method; | 2132 final String method; |
2133 final Uri location; | 2133 final Uri location; |
2134 } | 2134 } |
OLD | NEW |