Fix Imgur Redirecting

This commit is contained in:
Kam committed 2024-03-08 05:16:48 -05:00
1 parent 5ed21bdf15
commit d25dcc9f6a
4 files changed
+39 -12

No files matched your search

@@ -131,14 +131,13 @@ public class ImageDownloadAlt extends SimpleTexture
connection.setRequestProperty("Content-Type", "image/png");
connection.setRequestProperty("Expect", "100-continue");
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
// Set user agent
// Modify Accept Redirect
if (isImgurLink(url)) {
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)");
}
else {
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("Accept", "*/*");
}
connection.connect();
if (connection.getResponseCode() / 100 != 2)
@@ -169,7 +168,7 @@ public class ImageDownloadAlt extends SimpleTexture
}
catch (Exception exception)
{
ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception);
ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception);
}
finally
{
@@ -184,6 +183,7 @@ public class ImageDownloadAlt extends SimpleTexture
this.imageThread.start();
}
// Check if the URL is an Imgur link
private static boolean isImgurLink(URL url) {
return url.getHost().endsWith("imgur.com");