OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 const int _HEADERS_BUFFER_SIZE = 8 * 1024; | 7 const int _HEADERS_BUFFER_SIZE = 8 * 1024; |
8 | 8 |
9 class _HttpIncoming extends Stream<List<int>> { | 9 class _HttpIncoming extends Stream<List<int>> { |
10 final int _transferLength; | 10 final int _transferLength; |
(...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1816 _proxyCredentials.removeAt(index); | 1816 _proxyCredentials.removeAt(index); |
1817 } | 1817 } |
1818 } | 1818 } |
1819 | 1819 |
1820 static String _findProxyFromEnvironment(Uri url, | 1820 static String _findProxyFromEnvironment(Uri url, |
1821 Map<String, String> environment) { | 1821 Map<String, String> environment) { |
1822 checkNoProxy(String option) { | 1822 checkNoProxy(String option) { |
1823 if (option == null) return null; | 1823 if (option == null) return null; |
1824 Iterator<String> names = option.split(",").map((s) => s.trim()).iterator; | 1824 Iterator<String> names = option.split(",").map((s) => s.trim()).iterator; |
1825 while (names.moveNext()) { | 1825 while (names.moveNext()) { |
1826 if (url.host.endsWith(names.current)) { | 1826 var name = names.current; |
| 1827 if ((name.startsWith("[") && |
| 1828 name.endsWith("]") && |
| 1829 "[${url.host}]" == name) || |
| 1830 (name.isNotEmpty && |
| 1831 url.host.endsWith(name))) { |
1827 return "DIRECT"; | 1832 return "DIRECT"; |
1828 } | 1833 } |
1829 } | 1834 } |
1830 return null; | 1835 return null; |
1831 } | 1836 } |
1832 | 1837 |
1833 checkProxy(String option) { | 1838 checkProxy(String option) { |
1834 if (option == null) return null; | 1839 if (option == null) return null; |
| 1840 option = option.trim(); |
| 1841 if (option.isEmpty) return null; |
1835 int pos = option.indexOf("://"); | 1842 int pos = option.indexOf("://"); |
1836 if (pos >= 0) { | 1843 if (pos >= 0) { |
1837 option = option.substring(pos + 3); | 1844 option = option.substring(pos + 3); |
1838 } | 1845 } |
1839 pos = option.indexOf("/"); | 1846 pos = option.indexOf("/"); |
1840 if (pos >= 0) { | 1847 if (pos >= 0) { |
1841 option = option.substring(0, pos); | 1848 option = option.substring(0, pos); |
1842 } | 1849 } |
1843 if (option.indexOf(":") == -1) option = "$option:1080"; | 1850 // Add default port if no port configured. |
| 1851 if (option.indexOf("[") == 0) { |
| 1852 var pos = option.lastIndexOf(":"); |
| 1853 if (option.indexOf("]") > pos) option = "$option:1080"; |
| 1854 } else { |
| 1855 if (option.indexOf(":") == -1) option = "$option:1080"; |
| 1856 } |
1844 return "PROXY $option"; | 1857 return "PROXY $option"; |
1845 } | 1858 } |
1846 | 1859 |
1847 // Default to using the process current environment. | 1860 // Default to using the process current environment. |
1848 if (environment == null) environment = _platformEnvironmentCache; | 1861 if (environment == null) environment = _platformEnvironmentCache; |
1849 | 1862 |
1850 String proxyCfg; | 1863 String proxyCfg; |
1851 | 1864 |
1852 String noProxy = environment["no_proxy"]; | 1865 String noProxy = environment["no_proxy"]; |
1853 if (noProxy == null) noProxy = environment["NO_PROXY"]; | 1866 if (noProxy == null) noProxy = environment["NO_PROXY"]; |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 proxy = proxy.substring(at + 1).trim(); | 2187 proxy = proxy.substring(at + 1).trim(); |
2175 int colon = userinfo.indexOf(":"); | 2188 int colon = userinfo.indexOf(":"); |
2176 if (colon == -1 || colon == 0 || colon == proxy.length - 1) { | 2189 if (colon == -1 || colon == 0 || colon == proxy.length - 1) { |
2177 throw new HttpException( | 2190 throw new HttpException( |
2178 "Invalid proxy configuration $configuration"); | 2191 "Invalid proxy configuration $configuration"); |
2179 } | 2192 } |
2180 username = userinfo.substring(0, colon).trim(); | 2193 username = userinfo.substring(0, colon).trim(); |
2181 password = userinfo.substring(colon + 1).trim(); | 2194 password = userinfo.substring(colon + 1).trim(); |
2182 } | 2195 } |
2183 // Look for proxy host and port. | 2196 // Look for proxy host and port. |
2184 int colon = proxy.indexOf(":"); | 2197 int colon = proxy.lastIndexOf(":"); |
2185 if (colon == -1 || colon == 0 || colon == proxy.length - 1) { | 2198 if (colon == -1 || colon == 0 || colon == proxy.length - 1) { |
2186 throw new HttpException( | 2199 throw new HttpException( |
2187 "Invalid proxy configuration $configuration"); | 2200 "Invalid proxy configuration $configuration"); |
2188 } | 2201 } |
2189 String host = proxy.substring(0, colon).trim(); | 2202 String host = proxy.substring(0, colon).trim(); |
| 2203 if (host.startsWith("[") && host.endsWith("]")) { |
| 2204 host = host.substring(1, host.length - 2); |
| 2205 } |
2190 String portString = proxy.substring(colon + 1).trim(); | 2206 String portString = proxy.substring(colon + 1).trim(); |
2191 int port; | 2207 int port; |
2192 try { | 2208 try { |
2193 port = int.parse(portString); | 2209 port = int.parse(portString); |
2194 } on FormatException catch (e) { | 2210 } on FormatException catch (e) { |
2195 throw new HttpException( | 2211 throw new HttpException( |
2196 "Invalid proxy configuration $configuration, " | 2212 "Invalid proxy configuration $configuration, " |
2197 "invalid port '$portString'"); | 2213 "invalid port '$portString'"); |
2198 } | 2214 } |
2199 proxies.add(new _Proxy(host, port, username, password)); | 2215 proxies.add(new _Proxy(host, port, username, password)); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2554 | 2570 |
2555 String _getHttpVersion() { | 2571 String _getHttpVersion() { |
2556 var version = Platform.version; | 2572 var version = Platform.version; |
2557 // Only include major and minor version numbers. | 2573 // Only include major and minor version numbers. |
2558 int index = version.indexOf('.', version.indexOf('.') + 1); | 2574 int index = version.indexOf('.', version.indexOf('.') + 1); |
2559 version = version.substring(0, index); | 2575 version = version.substring(0, index); |
2560 return 'Dart/$version (dart:io)'; | 2576 return 'Dart/$version (dart:io)'; |
2561 } | 2577 } |
2562 | 2578 |
2563 | 2579 |
OLD | NEW |