// Instance Data ///////////////////////////////////////////////////////////////////////////////////////////////
final String originalUrl; ///< the URL as passed to the original constructor; this is never changed
- URL url = null; ///< the URL to connect to; this is munged when the url is parsed */
+ String url = null; ///< the URL to connect to; this is munged when the url is parsed */
String host = null; ///< the host to connect to
int port = -1; ///< the port to connect on
boolean ssl = false; ///< true if SSL (HTTPS) should be used
if (Log.verbose) Log.info(this, "evaluating PAC script");
String pac = null;
try {
- Object obj = pacFunc.call(url.toString(), url.getHost(), null, null, 2);
+ Object obj = pacFunc.call(url, host, null, null, 2);
if (Log.verbose) Log.info(this, " PAC script returned \"" + obj + "\"");
pac = obj.toString();
} catch (Throwable e) {
}
if (url.startsWith("https:")) {
- this.url = new URL("http" + url.substring(5));
ssl = true;
} else if (!url.startsWith("http:")) {
- throw new MalformedURLException("HTTP only supports http/https urls");
+ throw new IOException("HTTP only supports http/https urls");
+ }
+ if (url.indexOf("://") == -1) throw new IOException("URLs must contain a ://");
+ String temphost = url.substring(url.indexOf("://") + 1);
+ path = temphost.substring(temphost.indexOf('/'));
+ temphost = temphost.substring(0, temphost.indexOf('/'));
+ if (temphost.indexOf(':') != -1) {
+ port = Integer.parseInt(temphost.substring(temphost.indexOf(':')+1));
+ temphost = temphost.substring(0, temphost.indexOf(':'));
} else {
- this.url = new URL(url);
+ port = ssl ? 443 : 80;
}
- if (!skipResolveCheck) resolveAndCheckIfFirewalled(this.url.getHost());
- port = this.url.getPort();
- path = this.url.getFile();
- if (port == -1) port = ssl ? 443 : 80;
- host = this.url.getHost();
+ if (!skipResolveCheck) resolveAndCheckIfFirewalled(temphost);
+ host = temphost;
if (Log.verbose) Log.info(this, "creating HTTP object for connection to " + host + ":" + port);
Proxy pi = Platform.detectProxy();
if (h.get("AUTHTYPE").equals("Basic")) {
if (authCache.get(originalUrl) != null) throw new HTTPException("username/password rejected");
- authCache.put(originalUrl, "Basic " + new String(Base64.encode(userInfo.getBytes("US-ASCII"))));
+ authCache.put(originalUrl, "Basic " + new String(Base64.encode(userInfo.getBytes("UTF8"))));
} else if (h.get("AUTHTYPE").equals("Digest")) {
if (authCache.get(originalUrl) != null && !"true".equals(h.get("stale")))
if (style.equals("Basic")) {
Proxy.Authorization.authorization2 =
- "Basic " + new String(Base64.encode(Proxy.Authorization.authorization.getBytes("US-ASCII")));
+ "Basic " + new String(Base64.encode(Proxy.Authorization.authorization.getBytes("UTF8")));
} else if (style.equals("Digest")) {
String A1 = Proxy.Authorization.authorization.substring(0, userInfo.indexOf(':')) + ":" + h.get("realm") + ":" +
}
private String H(String s) throws IOException {
- byte[] b = s.getBytes("US-ASCII");
+ byte[] b = s.getBytes("UTF8");
MD5Digest md5 = new MD5Digest();
md5.update(b, 0, b.length);
byte[] out = new byte[md5.getDigestSize()];
*/
private static byte[] lmHash(String password) {
/*
- byte[] oemPassword = password.toUpperCase().getBytes("US-ASCII");
+ byte[] oemPassword = password.toUpperCase().getBytes("UTF8");
int length = java.lang.Math.min(oemPassword.length, 14);
byte[] keyBytes = new byte[14];
System.arraycopy(oemPassword, 0, keyBytes, 0, length);
Key lowKey = createDESKey(keyBytes, 0);
Key highKey = createDESKey(keyBytes, 7);
- byte[] magicConstant = "KGS!@#$%".getBytes("US-ASCII");
+ byte[] magicConstant = "KGS!@#$%".getBytes("UTF8");
Cipher des = Cipher.getInstance("DES/ECB/NoPadding");
des.init(Cipher.ENCRYPT_MODE, lowKey);
byte[] lowHash = des.doFinal(magicConstant);