Browse Source

only enable transparent gzip encoding when explicitly specified

fixes bugzilla issue 57048
master
Stefan Bodewig 10 years ago
parent
commit
faedd2bc5b
3 changed files with 36 additions and 2 deletions
  1. +8
    -0
      WHATSNEW
  2. +9
    -0
      manual/Tasks/get.html
  3. +19
    -2
      src/main/org/apache/tools/ant/taskdefs/Get.java

+ 8
- 0
WHATSNEW View File

@@ -13,6 +13,14 @@ Changes that could break older environments:
on Ant silently ignoring all but the first character.
Bugzilla Report 56584

* The changes that added <get>'s support for gzip encoding
automatically uncompressed content that would not have been touched
before - like when downloading .tar.gz files. A new flag has been
added to control the behavior and its default will make <get> work
as it did in 1.9.3. I.e. if you want it to work like 1.9.4
you have to explicitly set tryGzipEncoding to true.
Bugzilla Report 57048

Fixed bugs:
-----------



+ 9
- 0
manual/Tasks/get.html View File

@@ -134,6 +134,15 @@ plain text' authentication is used. This is only secure over an HTTPS link.
<em>since Ant 1.9.3</em></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">tryGzipEncoding</td>
<td valign="top">When set to true Ant will tell the server it is
willing to accept gzip encoding to reduce the amount of data to
transfer and uncompress the content transparently.<br/>
Setting this to true also means Ant will uncompress
<code>.tar.gz</code> and similar files automatically.<br/>
<em>since Ant 1.9.5</em></td>
<td align="center" valign="top">No; default "false"</td>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>any resource collection</h4>


+ 19
- 2
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -83,6 +83,7 @@ public class Get extends Task {
private int numberRetries = NUMBER_RETRIES;
private boolean skipExisting = false;
private boolean httpUseCaches = true; // on by default
private boolean tryGzipEncoding = false;
private Mapper mapperElement = null;
private String userAgent =
System.getProperty(MagicNames.HTTP_AGENT_PROPERTY,
@@ -459,6 +460,19 @@ public class Get extends Task {
this.httpUseCaches = httpUseCache;
}

/**
* Whether to transparently try to reduce bandwidth by telling the
* server ant would support gzip encoding.
*
* <p>Setting this to true also means Ant will uncompress
* <code>.tar.gz</code> and similar files automatically.</p>
*
* @since Ant 1.9.5
*/
public void setTryGzipEncoding(boolean b) {
tryGzipEncoding = b;
}

/**
* Define the mapper to map source to destination files.
* @return a mapper to be configured.
@@ -699,7 +713,9 @@ public class Get extends Task {
+ encoding);
}

connection.setRequestProperty("Accept-Encoding", GZIP_CONTENT_ENCODING);
if (tryGzipEncoding) {
connection.setRequestProperty("Accept-Encoding", GZIP_CONTENT_ENCODING);
}

if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection)
@@ -791,7 +807,8 @@ public class Get extends Task {
getLocation());
}

if (GZIP_CONTENT_ENCODING.equals(connection.getContentEncoding())) {
if (tryGzipEncoding
&& GZIP_CONTENT_ENCODING.equals(connection.getContentEncoding())) {
is = new GZIPInputStream(is);
}



Loading…
Cancel
Save