Index: . =================================================================== --- . (revision 696168) +++ . (working copy) @@ -39,10 +39,10 @@ import org.apache.ivy.util.Message; /** - * + * */ public class BasicURLHandler extends AbstractURLHandler { - + private static final Pattern ESCAPE_PATTERN = Pattern.compile("%25([0-9a-fA-F][0-9a-fA-F])"); private static final int BUFFER_SIZE = 64 * 1024; @@ -51,7 +51,7 @@ static final int SC_OK = 200; static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; - + private HttpStatus() { } } @@ -56,7 +56,13 @@ } } + private int requestMethod; + public BasicURLHandler() { + this(REQUEST_METHOD_HEAD); + } + + public BasicURLHandler(int requestMethod) { Message.debug("installing " + IvyAuthenticator.INSTANCE.getClass()); // do not remove, // ensure // IvyAuthenticator @@ -61,6 +67,7 @@ // ensure // IvyAuthenticator // class loading! + this.requestMethod = requestMethod; } public URLInfo getURLInfo(URL url) { @@ -75,7 +82,11 @@ con.setRequestProperty("User-Agent", "Apache Ivy/" + Ivy.getIvyVersion()); if (con instanceof HttpURLConnection) { HttpURLConnection httpCon = (HttpURLConnection) con; - httpCon.setRequestMethod("HEAD"); + + if (this.requestMethod == REQUEST_METHOD_HEAD) { + httpCon.setRequestMethod("HEAD"); + } + if (checkStatusCode(url, httpCon)) { return new URLInfo(true, httpCon.getContentLength(), con.getLastModified()); } @@ -83,9 +94,8 @@ int contentLength = con.getContentLength(); if (contentLength <= 0) { return UNAVAILABLE; - } else { - return new URLInfo(true, contentLength, con.getLastModified()); } + return new URLInfo(true, contentLength, con.getLastModified()); } } catch (UnknownHostException e) { Message.warn("Host " + e.getMessage() + " not found. url=" + url); @@ -101,10 +111,10 @@ private URL normalize(URL url) throws IOException { if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol())) { - try { - URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), + try { + URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); - + // it is possible that the original url was already (partial) escaped, // so we must unescape all '%' followed by 2 hexadecimals... String uriString = uri.toString(); @@ -110,9 +120,9 @@ String uriString = uri.toString(); url = new URL(ESCAPE_PATTERN.matcher(uriString).replaceAll("%$1")); } catch (URISyntaxException e) { - IOException ioe = new MalformedURLException("Couldn't convert '" - + url.toString() + "' to a valid URI"); - ioe.initCause(e); + IOException ioe = new MalformedURLException("Couldn't convert '" + + url.toString() + "' to a valid URI"); + ioe.initCause(e); throw ioe; } } @@ -253,4 +263,12 @@ } } + public int getRequestMethod() { + return this.requestMethod; + } + + public void setRequestMethod(int requestMethod) { + this.requestMethod = requestMethod; + } + }