set flag on URLConnection indicating that redirects should be followed (part of patch for issue #196)

Former-commit-id: 52758186ebf2f818b6cf107af1e12b92e3c2e370
This commit is contained in:
Jeremy Long
2015-02-18 20:11:30 -05:00
parent 085ab48f3f
commit 2caccab85f

View File

@@ -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 <jeremy.long@owasp.org>
*/
@@ -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);
}