GetTask 应当遵循 Content-Type 中的字符集设置 (#4183)

This commit is contained in:
Glavo
2025-08-04 20:28:46 +08:00
committed by GitHub
parent 0bd2adc3c6
commit a0ddaf6766
2 changed files with 2 additions and 4 deletions

View File

@@ -29,8 +29,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* @author huangyuhui * @author huangyuhui
*/ */
@@ -74,7 +72,7 @@ public final class GetTask extends FetchTask<String> {
public void close() throws IOException { public void close() throws IOException {
if (!isSuccess()) return; if (!isSuccess()) return;
String result = baos.toString(UTF_8); String result = baos.toString(NetworkUtils.getCharsetFromContentType(connection.getContentType()));
setResult(result); setResult(result);
if (checkETag) { if (checkETag) {

View File

@@ -303,7 +303,7 @@ public final class NetworkUtils {
static final Pattern CHARSET_REGEX = Pattern.compile("\\s*(charset)\\s*=\\s*['|\"]?(?<charset>[^\"^';,]+)['|\"]?"); static final Pattern CHARSET_REGEX = Pattern.compile("\\s*(charset)\\s*=\\s*['|\"]?(?<charset>[^\"^';,]+)['|\"]?");
static Charset getCharsetFromContentType(String contentType) { public static Charset getCharsetFromContentType(String contentType) {
if (contentType == null || contentType.isBlank()) if (contentType == null || contentType.isBlank())
return UTF_8; return UTF_8;