Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions http/normalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/klauspost/compress/zlib"
"github.com/klauspost/compress/zstd"
"github.com/pkg/errors"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"

Expand Down Expand Up @@ -168,6 +169,10 @@ func wrapDecodeReader(resp *http.Response) (rc io.ReadCloser, err error) {
if isContentTypeGbk(resp.Header.Get("Content-Type")) {
rc = io.NopCloser(transform.NewReader(rc, simplifiedchinese.GBK.NewDecoder()))
}
// handle Windows-1251 encoding
if isContentTypeWindows1251(resp.Header.Get("Content-Type")) {
rc = io.NopCloser(transform.NewReader(rc, charmap.Windows1251.NewDecoder()))
}
return rc, nil
}

Expand All @@ -176,3 +181,9 @@ func isContentTypeGbk(contentType string) bool {
contentType = strings.ToLower(contentType)
return stringsutil.ContainsAny(contentType, "gbk", "gb2312", "gb18030")
}

// isContentTypeWindows1251 checks if the content-type header is Windows-1251.
func isContentTypeWindows1251(contentType string) bool {
contentType = strings.ToLower(contentType)
return stringsutil.ContainsAny(contentType, "windows-1251", "cp1251", "cp-1251")
}
Loading