/** * Examine the given URL and replace the host with a non-loopback host if possible. It is checked, * whether the port is open as well. * <p/> * A replaced host uses the IP address instead of a (possibly non resolvable) name. * * @param pRequestURL url to examine and to update * @return the 'sane' URL (or the original one if no san */ public static String sanitizeLocalUrl(String pRequestURL) { try { URL url = new URL(pRequestURL); String host = url.getHost(); int port = getPort(url); InetAddress address = findLocalAddressListeningOnPort(host, port); return new URL(url.getProtocol(), address.getHostAddress(), port, url.getFile()).toExternalForm(); } catch (IOException e) { // Best effort, we at least tried it return pRequestURL; } }
/** * Examine the given URL and replace the host with a non-loopback host if possible. It is checked, * whether the port is open as well. * <p/> * A replaced host uses the IP address instead of a (possibly non resolvable) name. * * @param pRequestURL url to examine and to update * @return the 'sane' URL (or the original one if no san */ public static String sanitizeLocalUrl(String pRequestURL) { try { URL url = new URL(pRequestURL); String host = url.getHost(); int port = getPort(url); InetAddress address = findLocalAddressListeningOnPort(host, port); return new URL(url.getProtocol(), address.getHostAddress(), port, url.getFile()).toExternalForm(); } catch (IOException e) { // Best effort, we at least tried it return pRequestURL; } }
/** * Examine the given URL and replace the host with a non-loopback host if possible. It is checked, * whether the port is open as well. * <p/> * A replaced host uses the IP address instead of a (possibly non resolvable) name. * * @param pRequestURL url to examine and to update * @return the 'sane' URL (or the original one if no san */ public static String sanitizeLocalUrl(String pRequestURL) { try { URL url = new URL(pRequestURL); String host = url.getHost(); int port = getPort(url); InetAddress address = findLocalAddressListeningOnPort(host, port); return new URL(url.getProtocol(), address.getHostAddress(), port, url.getFile()).toExternalForm(); } catch (IOException e) { // Best effort, we at least tried it return pRequestURL; } }