Returns the authority with the host part converted to ASCII (Punycode). @param authority authority string ([userinfo@]host[:port]) @return ASCII-encoded authority, or the original string if encoding fails
(final String authority)
| 319 | * @return ASCII-encoded authority, or the original string if encoding fails |
| 320 | */ |
| 321 | private static String asciiAuthority(final String authority) { |
| 322 | final int at = authority.indexOf('@'); |
| 323 | final String userInfo = at < 0 ? "" : authority.substring(0, at + 1); |
| 324 | final String hostPort = at < 0 ? authority : authority.substring(at + 1); |
| 325 | // skip IPv6 brackets when searching for the port colon |
| 326 | final int bracket = hostPort.lastIndexOf(']'); |
| 327 | final int colon = hostPort.indexOf(':', Math.max(0, bracket)); |
| 328 | final String host = colon < 0 ? hostPort : hostPort.substring(0, colon); |
| 329 | final String port = colon < 0 ? "" : hostPort.substring(colon); |
| 330 | try { |
| 331 | return userInfo + IDN.toASCII(host) + port; |
| 332 | } catch(final IllegalArgumentException ex) { |
| 333 | Util.debug(ex); |
| 334 | return authority; |
| 335 | } |
| 336 | } |
| 337 | } |