MangaHub: fix 4.3 infinite loop
authorNiki Roo <niki@nikiroo.be>
Fri, 3 Apr 2020 21:16:14 +0000 (23:16 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 3 Apr 2020 21:16:14 +0000 (23:16 +0200)
src/be/nikiroo/fanfix/supported/MangaHub.java

index 437914ac3da77a68f4285d7baea601d3fd4ba4df..99e85693e1e819de4b3c08d1c638608c2f0cbac9 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Map.Entry;
 import org.jsoup.nodes.Element;
 
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
@@ -186,14 +187,20 @@ class MangaHub extends BasicSupport {
        }
 
        // HTTP response code, or -1 if other error
+       // TODO: move that to Downloader?
        private int getHttpStatus(URL url) {
                try {
-                       HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+                       HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                        try {
-                               connection.setRequestMethod("HEAD");
-                               return connection.getResponseCode();
+                               conn.setRequestMethod("HEAD");
+                               conn.setRequestProperty("User-Agent", Instance.getConfig().getString(Config.NETWORK_USER_AGENT));
+                               conn.setRequestProperty("Accept-Encoding", "gzip");
+                               conn.setRequestProperty("Accept", "*/*");
+                               conn.setRequestProperty("Charset", "utf-8");
+
+                               return conn.getResponseCode();
                        } finally {
-                               connection.disconnect();
+                               conn.disconnect();
                        }
                } catch (Exception e) {
                        return -1;