From 8315d43f549cb5638575c1476ecafaa07d6d63ef Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Mon, 29 Oct 2012 21:55:05 -0400 Subject: [PATCH] Added the Accept-Encoding header to speed up downloads Former-commit-id: 669fed48dcf120c5a1bef0e6073e0107afd0db4a --- .../org/codesecure/dependencycheck/utils/Downloader.java | 5 ++++- .../dependencycheck/utils/DownloaderIntegrationTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java b/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java index 84f199d6b..e8ead8c8c 100644 --- a/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java +++ b/src/main/java/org/codesecure/dependencycheck/utils/Downloader.java @@ -31,6 +31,7 @@ import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; +import java.util.zip.InflaterInputStream; /** * A utility to download files from the Internet. @@ -129,8 +130,10 @@ public class Downloader { BufferedOutputStream writer = null; try { InputStream reader; - if (unzip) { + if (unzip || (encoding != null && "gzip".equalsIgnoreCase(encoding))) { reader = new GZIPInputStream(conn.getInputStream()); + } else if (encoding != null && "deflate".equalsIgnoreCase(encoding)) { + reader = new InflaterInputStream(conn.getInputStream()); } else { reader = conn.getInputStream(); } diff --git a/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java b/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java index c9751256f..a360c519a 100644 --- a/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java +++ b/src/test/java/org/codesecure/dependencycheck/utils/DownloaderIntegrationTest.java @@ -52,7 +52,7 @@ public class DownloaderIntegrationTest { // Settings.setString(Settings.KEYS.PROXY_URL, "127.0.0.1"); //URL url = new URL(Settings.getString(Settings.KEYS.CPE_URL)); - URL url = new URL("http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-modified.xml"); + URL url = new URL("http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-2010.xml"); String outputPath = "target\\downloaded_cpe.xml"; Downloader.fetchFile(url, outputPath);