/** * {@link CookieOrigin} doesn't like empty hosts and negative ports, * but these things happen if we're dealing with a local file. * This method allows us to work around this limitation in HttpClient by feeding it a bogus host and port. * * @param url the URL to replace if necessary * @return the replacement URL, or the original URL if no replacement was necessary */ public URL replaceForCookieIfNecessary(URL url) { final String protocol = url.getProtocol(); final boolean file = "file".equals(protocol); if (file) { try { url = UrlUtils.getUrlWithNewHostAndPort(url, HtmlUnitBrowserCompatCookieSpec.LOCAL_FILESYSTEM_DOMAIN, 0); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return url; }
/** * {@link CookieOrigin} doesn't like empty hosts and negative ports, * but these things happen if we're dealing with a local file. * This method allows us to work around this limitation in HttpClient by feeding it a bogus host and port. * * @param url the URL to replace if necessary * @return the replacement URL, or the original URL if no replacement was necessary */ public URL replaceForCookieIfNecessary(URL url) { final String protocol = url.getProtocol(); final boolean file = "file".equals(protocol); if (file) { try { url = UrlUtils.getUrlWithNewHostAndPort(url, HtmlUnitBrowserCompatCookieSpec.LOCAL_FILESYSTEM_DOMAIN, 0); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return url; }
/** * Sets the host portion of the link's URL (the '[hostname]:[port]' portion). * @param host the new host portion of the link's URL * @throws Exception if an error occurs * @see <a href="http://msdn.microsoft.com/en-us/library/ms533784.aspx">MSDN Documentation</a> */ @JsxSetter public void setHost(final String host) throws Exception { final String hostname; final int port; final int index = host.indexOf(':'); if (index != -1) { hostname = host.substring(0, index); port = Integer.parseInt(host.substring(index + 1)); } else { hostname = host; port = -1; } final URL url = UrlUtils.getUrlWithNewHostAndPort(getUrl(), hostname, port); setUrl(url); }
/** * Sets the host portion of the location URL (the '[hostname]:[port]' portion). * @param host the new host portion of the location URL * @throws Exception if an error occurs * @see <a href="http://msdn.microsoft.com/en-us/library/ms533784.aspx">MSDN Documentation</a> */ @JsxSetter public void setHost(final String host) throws Exception { final String hostname; final int port; final int index = host.indexOf(':'); if (index != -1) { hostname = host.substring(0, index); port = Integer.parseInt(host.substring(index + 1)); } else { hostname = host; port = -1; } final URL url = UrlUtils.getUrlWithNewHostAndPort(getUrl(), hostname, port); setUrl(url); }
/** * Sets the host portion of the link's URL (the '[hostname]:[port]' portion). * @param host the new host portion of the link's URL * @throws Exception if an error occurs * @see <a href="http://msdn.microsoft.com/en-us/library/ms533784.aspx">MSDN Documentation</a> */ @JsxSetter public void setHost(final String host) throws Exception { final String hostname; final int port; final int index = host.indexOf(':'); if (index != -1) { hostname = host.substring(0, index); port = Integer.parseInt(host.substring(index + 1)); } else { hostname = host; port = -1; } final URL url = UrlUtils.getUrlWithNewHostAndPort(getUrl(), hostname, port); setUrl(url); }
/** * Sets the host portion of the location URL (the '[hostname]:[port]' portion). * @param host the new host portion of the location URL * @throws Exception if an error occurs * @see <a href="http://msdn.microsoft.com/en-us/library/ms533784.aspx">MSDN Documentation</a> */ @JsxSetter public void setHost(final String host) throws Exception { final String hostname; final int port; final int index = host.indexOf(':'); if (index != -1) { hostname = host.substring(0, index); port = Integer.parseInt(host.substring(index + 1)); } else { hostname = host; port = -1; } final URL url = UrlUtils.getUrlWithNewHostAndPort(getUrl(), hostname, port); setUrl(url); }