X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProxy.java;h=750b3eef6a37c874b69b485e8f30b9c41ca47946;hb=c60b070de7344284b8467ebe3653447b58df5a6c;hp=f6ce11b3666bf05e83aadab852219ecdc4867832;hpb=94c44e42bf9d13fb372733318d9667c35af266be;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/utils/Proxy.java b/src/be/nikiroo/utils/Proxy.java
old mode 100755
new mode 100644
index f6ce11b..750b3ee
--- a/src/be/nikiroo/utils/Proxy.java
+++ b/src/be/nikiroo/utils/Proxy.java
@@ -9,6 +9,64 @@ import java.net.PasswordAuthentication;
* @author niki
*/
public class Proxy {
+ /**
+ * Use the proxy described by this string:
+ *
+ * - ((user(:pass)@)proxy:port)
+ * - System proxy is noted :
+ *
+ * Some examples:
+ *
+ * - â do not use any proxy
+ * - : â use the system proxy
+ * - user@prox.com â use the proxy "prox.com" with default port
+ * and user "user"
+ * - prox.com:8080 â use the proxy "prox.com" on port 8080
+ * - user:pass@prox.com:8080 â use "prox.com" on port 8080
+ * authenticated as "user" with password "pass"
+ * - user:pass@: â use the system proxy authenticated as user
+ * "user" with password "pass"
+ *
+ *
+ * @param proxy
+ * the proxy
+ */
+ static public void use(String proxy) {
+ if (proxy != null && !proxy.isEmpty()) {
+ String user = null;
+ String password = null;
+ int port = 8080;
+
+ if (proxy.contains("@")) {
+ int pos = proxy.indexOf("@");
+ user = proxy.substring(0, pos);
+ proxy = proxy.substring(pos + 1);
+ if (user.contains(":")) {
+ pos = user.indexOf(":");
+ password = user.substring(pos + 1);
+ user = user.substring(0, pos);
+ }
+ }
+
+ if (proxy.equals(":")) {
+ proxy = null;
+ } else if (proxy.contains(":")) {
+ int pos = proxy.indexOf(":");
+ try {
+ port = Integer.parseInt(proxy.substring(0, pos));
+ proxy = proxy.substring(pos + 1);
+ } catch (Exception e) {
+ }
+ }
+
+ if (proxy == null) {
+ Proxy.useSystemProxy(user, password);
+ } else {
+ Proxy.useProxy(proxy, port, user, password);
+ }
+ }
+ }
+
/**
* Use the system proxy.
*/