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

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

Issue 12866005: Add a function for finding the HTTP proxy server from environment variables (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_proxy_configuration_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 1f794570966bd9fc7259047a629568abcc8b79e3..c1272d3e12a7bb28d34e22eef687cb07e2ed1b25 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -1258,6 +1258,56 @@ class _HttpClient implements HttpClient {
_credentials.removeAt(index);
}
}
+
+ static String _findProxyFromEnvironment(Uri url,
+ Map<String, String> environment) {
+ checkNoProxy(String option) {
+ if (option == null) return null;
+ Iterator<String> names = option.split(",").map((s) => s.trim()).iterator;
+ while (names.moveNext()) {
+ if (url.domain.endsWith(names.current)) {
+ return "DIRECT";
+ }
+ }
+ return null;
+ }
+
+ checkProxy(String option) {
+ if (option == null) return null;
+ int pos = option.indexOf("://");
+ if (pos >= 0) {
+ option = option.substring(pos + 3);
+ }
+ if (option.indexOf(":") == -1) option = "$option:1080";
+ return "PROXY $option";
+ }
+
+ // Default to using the process current environment.
+ if (environment == null) environment = Platform.environment;
+
+ String proxyCfg;
+
+ String noProxy = environment["no_proxy"];
+ if (noProxy == null) noProxy = environment["NO_PROXY"];
+ if ((proxyCfg = checkNoProxy(noProxy)) != null) {
+ return proxyCfg;
+ }
+
+ if (url.scheme == "http") {
+ String proxy = environment["http_proxy"];
+ if (proxy == null) proxy = environment["HTTP_PROXY"];
+ if ((proxyCfg = checkProxy(proxy)) != null) {
+ return proxyCfg;
+ }
+ } else if (url.scheme == "https") {
+ String proxy = environment["https_proxy"];
+ if (proxy == null) proxy = environment["HTTPS_PROXY"];
+ if ((proxyCfg = checkProxy(proxy)) != null) {
+ return proxyCfg;
+ }
+ }
+ return "DIRECT";
+ }
}
« no previous file with comments | « sdk/lib/io/http.dart ('k') | tests/standalone/io/http_proxy_configuration_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698