Merge branch 'subtree'
[fanfix.git] / src / be / nikiroo / utils / Downloader.java
index c9a319aa0eb725159287562ae76718fc531c8097..4191d0aea0da85511e2741c50c2a6c83806f612f 100644 (file)
@@ -39,7 +39,7 @@ public class Downloader {
         *            the User-Agent to use to download the resources -- note that
         *            some websites require one, some actively blacklist real UAs
         *            like the one from wget, some whitelist a couple of browsers
-        *            only (!)
+        *            only (!) -- can be NULL
         */
        public Downloader(String UA) {
                this(UA, null);
@@ -52,7 +52,7 @@ public class Downloader {
         *            the User-Agent to use to download the resources -- note that
         *            some websites require one, some actively blacklist real UAs
         *            like the one from wget, some whitelist a couple of browsers
-        *            only (!)
+        *            only (!) -- can be NULL
         * @param cache
         *            the {@link Cache} to use for all access (can be NULL)
         */
@@ -281,7 +281,9 @@ public class Downloader {
                        }
                }
 
-               if (offline) {
+               String protocol = originalUrl == null ? null : originalUrl
+                               .getProtocol();
+               if (isOffline() && !"file".equalsIgnoreCase(protocol)) {
                        tracer.error("Downloader OFFLINE, cannot proceed to URL: " + url);
                        throw new IOException("Downloader is currently OFFLINE, cannot download: " + url);
                }
@@ -431,7 +433,9 @@ public class Downloader {
                        conn.setRequestProperty("Cookie", cookies);
                }
 
-               conn.setRequestProperty("User-Agent", UA);
+               if (UA != null) {
+                       conn.setRequestProperty("User-Agent", UA);
+               }
                conn.setRequestProperty("Accept-Encoding", "gzip");
                conn.setRequestProperty("Accept", "*/*");
                conn.setRequestProperty("Charset", "utf-8");