Browse Source

bz-65489 http condition - don't follow redirects when followRedirects is set to false

master
Jaikiran Pai 3 years ago
parent
commit
83b157b47f
3 changed files with 42 additions and 1 deletions
  1. +7
    -0
      WHATSNEW
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/condition/Http.java
  3. +34
    -0
      src/tests/antunit/taskdefs/condition/http-test.xml

+ 7
- 0
WHATSNEW View File

@@ -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:
--------------



+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/condition/Http.java View File

@@ -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)) {


+ 34
- 0
src/tests/antunit/taskdefs/condition/http-test.xml View File

@@ -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>

Loading…
Cancel
Save