On 2005.07.12., at 6:27, [EMAIL PROTECTED] wrote:
Just wondering if HttpClient is able to do automatic proxy
configuration,
i.e. steal the proxy settings from the default browser?
If not, is there any plan to implement such a feature?
Here is my own proxy detection method. It reads all info from system
properties. It works on Java 1.4.2 but on Java 1.5 doesn't because
Java 1.5 doesn't store proxy information in system properties AFAIK.
But correct me if I'm wrong.
Here's my code:
public void detectProxy(Properties p) {
ArrayList proxies = new ArrayList();
if (p.containsKey("http.proxyHost")) {
HashMap pm = new HashMap();
/*
* http.agent = Mozilla/4.0 (Mac OS X 10.4.1)
* http.auth.serializeRequests = true
* http.nonProxyHosts = www|*.www|monarakh.hu|
*.monarakh.hu|core0|*.core0|core1|*.core1|10.0.0.2|127.0.0.1
* http.proxyHost = core0
* http.proxyPort = 3128
* https.protocols = SSLv3,SSLv2Hello
* https.proxyHost = core0
* https.proxyPort = 3128
*/
try {
HashMap m = new HashMap();
m.put("host", p.getProperty("http.proxyHost"));
m.put("port", p.getProperty("http.proxyPort"));
pm.put("http", m);
} catch (Exception exc) {
// debug
System.out.println(getClass() + ": failed to set
http proxy setting, exc="+ exc);
}
try {
HashMap m = new HashMap();
m.put("host", p.getProperty("https.proxyHost"));
m.put("port", p.getProperty("https.proxyPort"));
pm.put("https", m);
} catch (Exception exc) {
// debug
System.out.println(getClass() + ": failed to set
https proxy setting, exc="+ exc);
}
// put("proxy.autodetected", pm);
proxies.add(pm);
}
if (p.containsKey("javaplugin.proxy.config.list")) {
HashMap pm = new HashMap();
/*
* javaplugin.proxy.config.bypass =
www,*.www,monarakh.hu,*.monarakh.hu,core0,*.core0,core1,*.core1,10.0.0.2
,127.0.0.1
* javaplugin.proxy.config.list =
http=core0:3128,https=core0:3128
* javaplugin.proxy.config.type = manual
* javaplugin.proxy.usebrowsersettings = true
*/
String str = p.getProperty("javaplugin.proxy.config.list");
if (str != null) {
if (str.length() > 0) {
String[] list = str.split(",");
for (int i=0; i<list.length; i++) {
String sel = null;
String key = null;
if (list[i].startsWith("http=")) {
sel = list[i].substring("http=".length());
key = "http";
} else if (list[i].startsWith("https=")) {
sel = list[i].substring("https=".length());
key = "https";
}
if (sel != null) {
// TODO: no we have host:port pairs.
take it apart and drop into a map
String[] ops = sel.split(":");
try {
HashMap m = new HashMap();
m.put("host", ops[0]);
m.put("port", ops[1]);
pm.put(key, m);
} catch (Exception exc) {
// debug
System.out.println(getClass() + ":
failed to set http proxy setting, exc="+ exc);
}
} else {
// debug
System.out.println(getClass() + ":
unknown proxy type: "+ list[i]);
}
}
} else {
// debug
System.out.println(getClass() + ":
<javaplugin.proxy.config.list> is empty!");
}
}
proxies.add(pm);
}
put("proxies", proxies);
}
Hope it helps,
Gábor
"Always forgive your enemies. Nothing annoys them so much. (Oscar
Wilde, 1854-1900)"