Browse Source

Convert feed encoding only if the charset is specified

Frédéric Guillot 8 years ago
parent
commit
99dfbdbb47
1 changed files with 10 additions and 3 deletions
  1. 10 3
      reader/http/response.go

+ 10 - 3
reader/http/response.go

@@ -4,8 +4,12 @@
 
 package http
 
-import "io"
-import "golang.org/x/net/html/charset"
+import (
+	"io"
+	"strings"
+
+	"golang.org/x/net/html/charset"
+)
 
 // Response wraps a server response.
 type Response struct {
@@ -41,5 +45,8 @@ func (r *Response) IsModified(etag, lastModified string) bool {
 
 // NormalizeBodyEncoding make sure the body is encoded in UTF-8.
 func (r *Response) NormalizeBodyEncoding() (io.Reader, error) {
-	return charset.NewReader(r.Body, r.ContentType)
+	if strings.Contains(r.ContentType, "charset=") {
+		return charset.NewReader(r.Body, r.ContentType)
+	}
+	return r.Body, nil
 }