mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Change image download headers.
- Simplified connection headers. - Added a config to fall back to the original connection headers.
This commit is contained in:
1 parent
3bd25c689b
commit
80ab2eaae9
2 files changed
+45
-11
No files matched your search
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.SimpleTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -101,18 +102,10 @@ public class ImageDownloadAlt extends SimpleTexture {
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
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");
|
||||
|
||||
// Modify Accept Redirect
|
||||
if (isImgurLink(url)) {
|
||||
connection.setRequestProperty("Accept", "*/*");
|
||||
}
|
||||
// Adding a config so people can switch back if needed.
|
||||
// TODO: Remove config option if improved works better
|
||||
connection = ConfigClient.ImprovedImageDownloadConnection ? setupConnectionImproved(url) : setupConnectionOld(url);
|
||||
|
||||
connection.connect();
|
||||
|
||||
@@ -152,6 +145,44 @@ public class ImageDownloadAlt extends SimpleTexture {
|
||||
this.imageThread.start();
|
||||
}
|
||||
|
||||
private HttpURLConnection setupConnectionOld(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
// setups stuff which basically tells the browser if this a get or post request
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
|
||||
// ??? I believe these are used to tell the receiver what you are sending to them
|
||||
// Not what you expect to receive from them.
|
||||
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");
|
||||
|
||||
// Modify Accept Redirect
|
||||
if (isImgurLink(url)) {
|
||||
connection.setRequestProperty("Accept", "*/*");
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private HttpURLConnection setupConnectionImproved(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
// Basically redundant because I set it as a GET request?
|
||||
// Better safe than sorry ig.
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
|
||||
// Random ass user agent I grabbed from my snooping on imgur
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0");
|
||||
// I tell the server what I want to receive.
|
||||
// TODO: Should this just accept PNGs?
|
||||
connection.setRequestProperty("Accept", "image/png,image/*");
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
// Check if the URL is an Imgur link
|
||||
private static boolean isImgurLink(URL url) {
|
||||
|
||||
@@ -157,6 +157,7 @@ public class ConfigClient {
|
||||
public static boolean LegacyTallLamp = false;
|
||||
public static boolean LegacyPedestal = false;
|
||||
public static boolean LegacyMailbox = false;
|
||||
public static boolean ImprovedImageDownloadConnection = true;
|
||||
|
||||
public static void init(File configFile) {
|
||||
config = new Configuration(configFile);
|
||||
@@ -303,6 +304,7 @@ public class ConfigClient {
|
||||
BannerAlerts = BannerAlertsProperty.getBoolean(true);
|
||||
|
||||
WoodTextures = config.get(TEXTURE, "Wood Textures", false, "Models like Chairs and Stools will use default MC Wood Textures").getBoolean(false);
|
||||
ImprovedImageDownloadConnection = config.get(TEXTURE, "DEBUG: Better handling of image downloads: ", true).getBoolean(true);
|
||||
|
||||
LegacyCampfire = config.get(MODEL, "Legacy Campfire Model", false).getBoolean(false);
|
||||
LegacyBanner = config.get(MODEL, "Legacy Banner Model", false).getBoolean(false);
|
||||
@@ -333,6 +335,7 @@ public class ConfigClient {
|
||||
FontSize = LegacyConfig.FontSize;
|
||||
FontSizeProperty.set(FontSize);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
FMLLog.log(Level.ERROR, e, "CNPC+ has had a problem loading its client configuration");
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user