+ port = req.getLocalPort();
+ if((port == 80) && scheme.equals("http"))
+ port = -1;
+ else if((port == 443) && scheme.equals("https"))
+ port = -1;
+ } else {
+ int p;
+ if((host.charAt(0) == '[') && ((p = host.indexOf(']', 1)) > 1)) {
+ String newhost = host.substring(1, p);
+ if((p = host.indexOf(':', p + 1)) >= 0) {
+ try {
+ port = Integer.parseInt(host.substring(p + 1));
+ } catch(NumberFormatException e) {}
+ }
+ host = newhost;
+ } else if((p = host.indexOf(':')) >= 0) {
+ try {
+ port = Integer.parseInt(host.substring(p + 1));
+ host = host.substring(0, p);
+ } catch(NumberFormatException e) {}
+ }
+ }