mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 08:27:45 +00:00
Better Imgur Handling
This commit is contained in:
1 parent
c692f86ff1
commit
d76416593f
1 file changed
+15
-2
@@ -124,13 +124,21 @@ public class ImageDownloadAlt extends SimpleTexture
|
||||
|
||||
try
|
||||
{
|
||||
connection = (HttpURLConnection)(new URL(ImageDownloadAlt.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
URL url = new URL(ImageDownloadAlt.this.imageUrl);
|
||||
connection = (HttpURLConnection)(url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
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
|
||||
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.connect();
|
||||
|
||||
if (connection.getResponseCode() / 100 != 2)
|
||||
@@ -175,4 +183,9 @@ public class ImageDownloadAlt extends SimpleTexture
|
||||
this.imageThread.setDaemon(true);
|
||||
this.imageThread.start();
|
||||
}
|
||||
|
||||
// Check if the URL is an Imgur link
|
||||
private static boolean isImgurLink(URL url) {
|
||||
return url.getHost().endsWith("imgur.com");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user