Declare Forge user agent (#5946)

This commit is contained in:
Chris H
2024-08-18 13:17:43 -04:00
committed by GitHub
parent 80cc302c99
commit d2178756b5
4 changed files with 9 additions and 4 deletions

View File

@@ -45,4 +45,8 @@ public class BuildInfo {
return StringUtils.containsIgnoreCase(forgeVersion, "git") ||
StringUtils.containsIgnoreCase(forgeVersion, "snapshot");
}
public static String getUserAgent() {
return "Forge/" + getVersionString();
}
}

View File

@@ -74,7 +74,7 @@ public class SwingImageFetcher extends ImageFetcher {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//connection.setConnectTimeout(1000 * 5); //wait 5 seconds the most
//connection.setReadTimeout(1000 * 5);
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
conn.setRequestProperty("User-Agent", BuildInfo.getUserAgent());
if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
imageurl = TextUtil.fastReplace(imageurl, ".full.jpg", ".fullborder.jpg");
conn.disconnect();

View File

@@ -37,7 +37,7 @@ public class LibGDXImageFetcher extends ImageFetcher {
URL url = new URL(urlToDownload);
System.out.println("Attempting to fetch: " + url);
java.net.URLConnection c = url.openConnection();
c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
c.setRequestProperty("User-Agent", BuildInfo.getUserAgent());
InputStream is = c.getInputStream();
// First, save to a temporary file so that nothing tries to read
@@ -64,7 +64,7 @@ public class LibGDXImageFetcher extends ImageFetcher {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//connection.setConnectTimeout(1000 * 5); //wait 5 seconds the most
//connection.setReadTimeout(1000 * 5);
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
conn.setRequestProperty("User-Agent", BuildInfo.getUserAgent());
if(conn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND)
imageurl = TextUtil.fastReplace(imageurl, ".full.jpg", ".fullborder.jpg");
conn.disconnect();

View File

@@ -5,6 +5,7 @@ import com.google.common.io.Files;
import forge.gui.FThreads;
import forge.gui.GuiBase;
import forge.gui.interfaces.IProgressBar;
import forge.util.BuildInfo;
import forge.util.FileUtil;
import java.io.*;
@@ -89,7 +90,7 @@ public class GuiDownloadZipService extends GuiDownloadService {
if (url.getPath().endsWith(".php")) {
//ensure file can be downloaded if returned from PHP script
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
conn.setRequestProperty("User-Agent", BuildInfo.getUserAgent());
}
conn.connect();