Skip to content
This repository was archived by the owner on Sep 9, 2023. It is now read-only.

Commit a20e59e

Browse files
Added user-agents
1 parent 4e1c4eb commit a20e59e

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/ml/northwestwind/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class Constants {
88
public static final String CURSEFORGE_API = "https://northwestwind.ml/api/curseforge/mods/";
9-
public static final String VERSION = "1.3.1";
9+
public static final String VERSION = "1.3.2";
1010
private static final String OS = System.getProperty("os.name").toLowerCase();
1111
public static final boolean IS_WINDOWS = (OS.contains("win"));
1212
public static final boolean IS_MAC = (OS.contains("mac"));

src/ml/northwestwind/Utils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.io.*;
1010
import java.net.HttpURLConnection;
11+
import java.net.MalformedURLException;
1112
import java.net.URL;
1213
import java.nio.charset.StandardCharsets;
1314
import java.util.Arrays;
@@ -49,6 +50,7 @@ public static String downloadFile(String fileURL, String saveDir) throws IOExcep
4950
public static String downloadFile(String fileURL, String saveDir, String name) throws IOException {
5051
URL url = new URL(fileURL.replace(" ", "%20"));
5152
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
53+
httpConn.addRequestProperty("User-Agent", "Mozilla/5.0");
5254
int responseCode = httpConn.getResponseCode();
5355
String saveFilePath = null;
5456

@@ -160,7 +162,7 @@ public static Object readJsonFromUrl(String url) {
160162

161163
public static Object readJsonFromUrl(String url, boolean printError) {
162164
JSONParser parser = new JSONParser();
163-
try (InputStream is = new URL(url).openStream()) {
165+
try (InputStream is = readStreamFromUrl(url)) {
164166
BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
165167
String jsonText = readAll(rd);
166168
return parser.parse(jsonText);
@@ -170,6 +172,12 @@ public static Object readJsonFromUrl(String url, boolean printError) {
170172
}
171173
}
172174

175+
private static InputStream readStreamFromUrl(String url) throws IOException {
176+
HttpURLConnection httpcon = (HttpURLConnection) new URL(url).openConnection();
177+
httpcon.addRequestProperty("User-Agent", "Mozilla/5.0");
178+
return httpcon.getInputStream();
179+
}
180+
173181
public static boolean isMCVersionValid(String ver) {
174182
String[] splitted = ver.replace("-Snapshot", "").split("\\.");
175183
if (splitted.length > 3) return false;

update.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
2+
"1.3.2": {
3+
"title": "Added User-Agent to requests",
4+
"description": "This should fix the 403 error some users are receiving."
5+
},
26
"1.3.1": {
37
"title": "Hotfix for profile update error"
48
},
59
"1.3.0": {
610
"title": "Better version control & Adapting to new API",
7-
"description": "You can now install modpacks with a modpack ZIP ID"
11+
"description": "You can now install modpacks with a modpack ZIP ID."
812
},
913
"1.2.12": {
1014
"title": "Fixed null downloadUrl",
@@ -54,5 +58,5 @@
5458
"1.2.0": {
5559
"title": "Update Checker & Profile Generator"
5660
},
57-
"latest": "1.3.1"
61+
"latest": "1.3.2"
5862
}

0 commit comments

Comments
 (0)