HttpRequests: disable java's followRedirects

This commit is contained in:
Ivan Chirkov
2017-07-27 00:00:03 +02:00
parent eed01c2123
commit 8a6e2998f1
@@ -501,12 +501,15 @@ public final class HttpRequests {
}
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
httpURLConnection.setInstanceFollowRedirects(false);
if (LOG.isDebugEnabled()) LOG.debug("connecting to " + url);
int responseCode = ((HttpURLConnection)connection).getResponseCode();
int responseCode = httpURLConnection.getResponseCode();
if (LOG.isDebugEnabled()) LOG.debug("response: " + responseCode);
if (responseCode < 200 || responseCode >= 300 && responseCode != HttpURLConnection.HTTP_NOT_MODIFIED) {
((HttpURLConnection)connection).disconnect();
httpURLConnection.disconnect();
if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {
request.myUrl = url = connection.getHeaderField("Location");