From 10e250f3b81492ab70b4ef730d4d5276f6400519 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 26 Aug 2009 10:26:35 +0000 Subject: [PATCH] Add httpusecaches attribute to . PR 41891 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807953 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ docs/manual/CoreTasks/get.html | 9 +++++++++ .../org/apache/tools/ant/taskdefs/Get.java | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 8e5452712..28db72a99 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -915,6 +915,10 @@ Other changes: channels. Bugzilla Report 30094. + * has a new attribute that can be used to disable caching on + HTTP connections at the HttpUrlConnection level. + Bugzilla Report 41891. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/CoreTasks/get.html b/docs/manual/CoreTasks/get.html index bc89e225b..4e602aeda 100644 --- a/docs/manual/CoreTasks/get.html +++ b/docs/manual/CoreTasks/get.html @@ -115,6 +115,15 @@ plain text' authentication is used. This is only secure over an HTTPS link. since Ant 1.8.0 No; default "false" + + httpusecaches + HTTP only - if true, allow caching at the + HttpUrlConnection level. if false, turn caching off.
+ Note this is only a hint to the underlying UrlConnection + class, implementations and proxies are free to ignore the + setting. + No; default "true" +

Examples

  <get src="http://ant.apache.org/" dest="help/index.html"/>
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java index f64a1272b..ca9550a6b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Get.java +++ b/src/main/org/apache/tools/ant/taskdefs/Get.java @@ -67,6 +67,7 @@ public class Get extends Task { private long maxTime = 0; private int numberRetries = NUMBER_RETRIES; private boolean skipExisting = false; + private boolean httpUseCaches = true; // on by default /** * Does the work. @@ -303,6 +304,20 @@ public class Get extends Task { this.skipExisting = s; } + /** + * HTTP connections only - control caching on the + * HttpUrlConnection: httpConnection.setUseCaches(); if false, do + * not allow caching on the HttpUrlConnection. + * + *

Defaults to true (allow caching, which is also the + * HttpUrlConnection default value.

+ * + * @since Ant 1.8.0 + */ + public void setHttpUseCaches(boolean httpUseCache) { + this.httpUseCaches = httpUseCache; + } + /** * Interface implemented for reporting * progess of downloading. @@ -507,6 +522,8 @@ public class Get extends Task { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection) .setInstanceFollowRedirects(false); + ((HttpURLConnection) connection) + .setUseCaches(httpUseCaches); } // connect to the remote site (may take some time) connection.connect(); @@ -514,8 +531,6 @@ public class Get extends Task { // First check on a 301 / 302 (moved) response (HTTP only) if (connection instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) connection; - // httpConnection.setInstanceFollowRedirects(false); - // httpConnection.setUseCaches(false); int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||