Skip to content

Commit 81b6152

Browse files
authored
使 NetworkUtils.doGet 支持更多 URI scheme (#4768)
1 parent d93f4d6 commit 81b6152

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/NetworkUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ public static URLConnection createConnection(URI uri) throws IOException {
144144
}
145145
connection.setConnectTimeout(TIME_OUT);
146146
connection.setReadTimeout(TIME_OUT);
147-
if (connection instanceof HttpURLConnection) {
148-
var httpConnection = (HttpURLConnection) connection;
147+
if (connection instanceof HttpURLConnection httpConnection) {
149148
httpConnection.setRequestProperty("Accept-Language", Locale.getDefault().toLanguageTag());
150149
httpConnection.setInstanceFollowRedirects(false);
151150
}
@@ -276,7 +275,11 @@ public static String doGet(String uri) throws IOException {
276275
}
277276

278277
public static String doGet(URI uri) throws IOException {
279-
return readFullyAsString(resolveConnection(createHttpConnection(uri)));
278+
URLConnection connection = createConnection(uri);
279+
if (connection instanceof HttpURLConnection httpURLConnection) {
280+
connection = resolveConnection(httpURLConnection);
281+
}
282+
return readFullyAsString(connection);
280283
}
281284

282285
public static String doGet(List<URI> uris) throws IOException {

0 commit comments

Comments
 (0)