This is an automated email from the ASF dual-hosted git repository.

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new 83b157b  bz-65489 http condition - don't follow redirects when 
followRedirects is set to false
83b157b is described below

commit 83b157b47fbbbdee6263b83fde487dc613015652
Author: Jaikiran Pai <[email protected]>
AuthorDate: Mon Aug 9 17:06:29 2021 +0530

    bz-65489 http condition - don't follow redirects when followRedirects is 
set to false
---
 WHATSNEW                                           |  7 +++++
 .../apache/tools/ant/taskdefs/condition/Http.java  |  2 +-
 src/tests/antunit/taskdefs/condition/http-test.xml | 34 ++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/WHATSNEW b/WHATSNEW
index abbf2b8..92f1c50 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -1,6 +1,13 @@
 Changes from Ant 1.10.11 TO Ant 1.10.12
 =======================================
 
+Fixed bugs:
+-----------
+
+ * The http condition would follow redirects even when "followRedirects" 
attribute
+   was set to "false". This has now been fixed.
+   Bugzilla Report 65489
+
 Other changes:
 --------------
 
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 a047dec..c7df122 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/Http.java
@@ -149,7 +149,7 @@ public class Http extends ProjectComponent implements 
Condition {
         http.setInstanceFollowRedirects(followRedirects);
         http.setReadTimeout(readTimeout);
         final int firstStatusCode = http.getResponseCode();
-        if (Get.isMoved(firstStatusCode)) {
+        if (this.followRedirects && Get.isMoved(firstStatusCode)) {
             final String newLocation = http.getHeaderField("Location");
             final URL newURL = new URL(newLocation);
             if (redirectionAllowed(url, newURL)) {
diff --git a/src/tests/antunit/taskdefs/condition/http-test.xml 
b/src/tests/antunit/taskdefs/condition/http-test.xml
index 91ec866..1b9f133 100644
--- a/src/tests/antunit/taskdefs/condition/http-test.xml
+++ b/src/tests/antunit/taskdefs/condition/http-test.xml
@@ -68,4 +68,38 @@
         text="Result code for ${unsecurelocation} was 200" />
   </target>
 
+  <target name="testDontFollowPermanentRedirect">
+    <sleep milliseconds="250"/>
+    <au:assertTrue>
+      <http url="${location}/permanent.txt" followRedirects="false"/>
+    </au:assertTrue>
+    <au:assertLogContains level="verbose"
+                          text="Result code for ${location}/permanent.txt was 
301" />
+  </target>
+
+  <target name="testDontFollowTemporaryRedirect">
+    <sleep milliseconds="250"/>
+    <au:assertTrue>
+      <http url="${location}/temp.txt" followRedirects="false"/>
+    </au:assertTrue>
+    <au:assertLogContains level="verbose"
+                          text="Result code for ${location}/temp.txt was 302" 
/>
+  </target>
+
+  <target name="testDontFollowStatusCode307Redirect">
+    <sleep milliseconds="250"/>
+    <au:assertTrue>
+      <http url="${location}/307.txt" followRedirects="false"/>
+    </au:assertTrue>
+    <au:assertLogContains level="verbose"
+                          text="Result code for ${location}/307.txt was 307" />
+  </target>
+
+  <target name="testDontFollowHttpToHttpsRedirect">
+    <sleep milliseconds="250"/>
+    <au:assertTrue>
+      <http url="${unsecurelocation}" followRedirects="false"/>
+    </au:assertTrue>
+  </target>
+
 </project>

Reply via email to