Browse Source

PR 54374: support status code 307 redirects in <get>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1429209 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 12 years ago
parent
commit
171220cb33
3 changed files with 21 additions and 1 deletions
  1. +3
    -0
      WHATSNEW
  2. +5
    -1
      src/main/org/apache/tools/ant/taskdefs/Get.java
  3. +13
    -0
      src/tests/antunit/taskdefs/get-test.xml

+ 3
- 0
WHATSNEW View File

@@ -56,6 +56,9 @@ Fixed bugs:
was empty.
Bugzilla Report 53626.

* <get> now supports HTTP redirects using status code 307.
Bugzilla Report 54374.

Other changes:
--------------



+ 5
- 1
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -58,6 +58,9 @@ public class Get extends Task {
private static final int BIG_BUFFER_SIZE = 100 * 1024;
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final int REDIRECT_LIMIT = 25;
// HttpURLConnection doesn't have a constant for this in Java5 and
// what it calls HTTP_MOVED_TEMP would better be FOUND
private static final int HTTP_MOVED_TEMP = 307;

private static final String HTTP = "http";
private static final String HTTPS = "https";
@@ -666,7 +669,8 @@ public class Get extends Task {
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
responseCode == HttpURLConnection.HTTP_SEE_OTHER)
responseCode == HttpURLConnection.HTTP_SEE_OTHER ||
responseCode == HTTP_MOVED_TEMP)
{
String newLocation = httpConnection.getHeaderField("Location");
String message = aSource


+ 13
- 0
src/tests/antunit/taskdefs/get-test.xml View File

@@ -64,6 +64,19 @@
<au:assertLogContains text="temp.txt moved to http" />
</target>
<target name="testStatusCode307Redirect">
<get src="${location}/307.txt" dest="${output}/307.txt"/>
<au:assertTrue>
<resourcecount count="1">
<restrict>
<file file="${output}/307.txt" />
<contains text="307 status code redirect succeeded" />
</restrict>
</resourcecount>
</au:assertTrue>
<au:assertLogContains text="307.txt moved to http" />
</target>
<target name="test5LevelsOfRedirect">
<get src="${location}/redir5.txt" dest="${output}/redir5.tmp"/>
<au:assertTrue>


Loading…
Cancel
Save