GetTask 应当遵循 Content-Type 中的字符集设置 (#4183)
This commit is contained in:
@@ -29,8 +29,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* @author huangyuhui
|
||||
*/
|
||||
@@ -74,7 +72,7 @@ public final class GetTask extends FetchTask<String> {
|
||||
public void close() throws IOException {
|
||||
if (!isSuccess()) return;
|
||||
|
||||
String result = baos.toString(UTF_8);
|
||||
String result = baos.toString(NetworkUtils.getCharsetFromContentType(connection.getContentType()));
|
||||
setResult(result);
|
||||
|
||||
if (checkETag) {
|
||||
|
||||
@@ -303,7 +303,7 @@ public final class NetworkUtils {
|
||||
|
||||
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())
|
||||
return UTF_8;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user