From 2caccab85fb82787a83c0b8021e5da35f338ee82 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Wed, 18 Feb 2015 20:11:30 -0500 Subject: [PATCH] set flag on URLConnection indicating that redirects should be followed (part of patch for issue #196) Former-commit-id: 52758186ebf2f818b6cf107af1e12b92e3c2e370 --- .../utils/URLConnectionFactory.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java index 06ddf1ddf..36f350bef 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java @@ -25,10 +25,11 @@ import java.net.PasswordAuthentication; import java.net.Proxy; import java.net.SocketAddress; import java.net.URL; +import java.net.URLConnection; /** - * A URLConnection Factory to create new connections. This encapsulates several configuration checks to ensure that the - * connection uses the correct proxy settings. + * A URLConnection Factory to create new connections. This encapsulates several configuration checks to ensure that the connection + * uses the correct proxy settings. * * @author Jeremy Long */ @@ -41,8 +42,8 @@ public final class URLConnectionFactory { } /** - * Utility method to create an HttpURLConnection. If the application is configured to use a proxy this method will - * retrieve the proxy settings and use them when setting up the connection. + * Utility method to create an HttpURLConnection. If the application is configured to use a proxy this method will retrieve + * the proxy settings and use them when setting up the connection. * * @param url the url to connect to * @return an HttpURLConnection @@ -79,6 +80,7 @@ public final class URLConnectionFactory { } final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000); conn.setConnectTimeout(timeout); + conn.setInstanceFollowRedirects(true); } catch (IOException ex) { if (conn != null) { try { @@ -93,8 +95,8 @@ public final class URLConnectionFactory { } /** - * Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a - * proxy is configured but we don't want to use it (for example, if there's an internal repository configured) + * Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is + * configured but we don't want to use it (for example, if there's an internal repository configured) * * @param url the URL to connect to * @param proxy whether to use the proxy (if configured) @@ -110,6 +112,7 @@ public final class URLConnectionFactory { conn = (HttpURLConnection) url.openConnection(); final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000); conn.setConnectTimeout(timeout); + conn.setInstanceFollowRedirects(true); } catch (IOException ioe) { throw new URLConnectionFailureException("Error getting connection.", ioe); }