From 89fb2d4915b21b01a329fc537396a156b59c179c Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 24 May 2014 07:06:46 -0400 Subject: [PATCH] fixed error messages and added status code checks Former-commit-id: d21ff11466908f07ca02a50269f08d76f16a243e --- .../java/org/owasp/dependencycheck/utils/Downloader.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java index 831530772..59fc9ec30 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java @@ -166,7 +166,7 @@ public final class Downloader { try { lastModifiedFile = new File(url.toURI()); } catch (URISyntaxException ex) { - final String msg = String.format("Unable to locate '%s'; is the cve.url-2.0.modified property set correctly?", url.toString()); + final String msg = String.format("Unable to locate '%s'", url.toString()); throw new DownloadFailedException(msg); } timestamp = lastModifiedFile.lastModified(); @@ -176,7 +176,12 @@ public final class Downloader { conn = URLConnectionFactory.createHttpURLConnection(url); conn.setRequestMethod("HEAD"); conn.connect(); - timestamp = conn.getLastModified(); + int t = conn.getResponseCode(); + if (t >= 200 && t < 300) { + timestamp = conn.getLastModified(); + } else { + throw new DownloadFailedException("HEAD request returned a non-200 status code"); + } } catch (URLConnectionFailureException ex) { throw new DownloadFailedException("Error creating URL Connection for HTTP HEAD request.", ex); } catch (IOException ex) {