From c78ecf75bbe9219626ebd80c34d9593d3c4b326d Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Sun, 7 Feb 2016 16:02:11 +0100
Subject: [PATCH] optionally don't follow redirects in
https://bz.apache.org/bugzilla/show_bug.cgi?id=58840
---
WHATSNEW | 3 +++
manual/Tasks/conditions.html | 7 +++++++
.../apache/tools/ant/taskdefs/condition/Http.java | 12 +++++++++++-
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/WHATSNEW b/WHATSNEW
index b74181ceb..9305bc16c 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -48,6 +48,9 @@ Other changes:
addition to filesets.
Bugzilla Report 50769
+ * The condition has a new optional attribute followRedirects.
+ Bugzilla Report 58840
+
Changes from Ant 1.9.5 TO Ant 1.9.6
===================================
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html
index 814072ecb..08d0bccec 100644
--- a/manual/Tasks/conditions.html
+++ b/manual/Tasks/conditions.html
@@ -229,6 +229,13 @@ of 400 or greater are viewed as invalid.
since Ant 1.8.0
No |
+
+ followRedirects |
+ Whether redirects should be followed. The default
+ is true
+ since Ant 1.9.7 |
+ No |
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Http.java b/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
index 1dc94204c..4c0427886 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
@@ -41,7 +41,7 @@ public class Http extends ProjectComponent implements Condition {
private String spec = null;
private String requestMethod = DEFAULT_REQUEST_METHOD;
-
+ private boolean followRedirects = true;
/**
* Set the url attribute
@@ -79,6 +79,15 @@ public class Http extends ProjectComponent implements Condition {
: method.toUpperCase(Locale.ENGLISH);
}
+ /**
+ * Whether redirects sent by the server should be followed,
+ * defaults to true.
+ * @since Ant 1.9.7
+ */
+ public void setFollowRedirects(boolean f) {
+ followRedirects = f;
+ }
+
/**
* @return true if the HTTP request succeeds
* @exception BuildException if an error occurs
@@ -95,6 +104,7 @@ public class Http extends ProjectComponent implements Condition {
if (conn instanceof HttpURLConnection) {
HttpURLConnection http = (HttpURLConnection) conn;
http.setRequestMethod(requestMethod);
+ http.setInstanceFollowRedirects(followRedirects);
int code = http.getResponseCode();
log("Result code for " + spec + " was " + code,
Project.MSG_VERBOSE);