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.Proxy;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
/** /**
* A URLConnection Factory to create new connections. This encapsulates several configuration checks to ensure that the * A URLConnection Factory to create new connections. This encapsulates several configuration checks to ensure that the connection
* connection uses the correct proxy settings. * uses the correct proxy settings.
* *
* @author Jeremy Long <jeremy.long@owasp.org> * @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 * Utility method to create an HttpURLConnection. If the application is configured to use a proxy this method will retrieve
* retrieve the proxy settings and use them when setting up the connection. * the proxy settings and use them when setting up the connection.
* *
* @param url the url to connect to * @param url the url to connect to
* @return an HttpURLConnection * @return an HttpURLConnection
@@ -79,6 +80,7 @@ public final class URLConnectionFactory {
} }
final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000); final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000);
conn.setConnectTimeout(timeout); conn.setConnectTimeout(timeout);
conn.setInstanceFollowRedirects(true);
} catch (IOException ex) { } catch (IOException ex) {
if (conn != null) { if (conn != null) {
try { 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 * Utility method to create an HttpURLConnection. The use of a proxy here is optional as there may be cases where a proxy is
* proxy is configured but we don't want to use it (for example, if there's an internal repository configured) * 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 url the URL to connect to
* @param proxy whether to use the proxy (if configured) * @param proxy whether to use the proxy (if configured)
@@ -110,6 +112,7 @@ public final class URLConnectionFactory {
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000); final int timeout = Settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 60000);
conn.setConnectTimeout(timeout); conn.setConnectTimeout(timeout);
conn.setInstanceFollowRedirects(true);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new URLConnectionFailureException("Error getting connection.", ioe); throw new URLConnectionFailureException("Error getting connection.", ioe);
} }