Skip to content

Commit c6e51fa

Browse files
committed
Removed iconv-go dependency and cgo dependency as a result. Not working yet.
1 parent 9adb5d9 commit c6e51fa

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

proxy.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
"strings"
1515

1616
"github.com/PuerkitoBio/goquery"
17-
"github.com/djimenez/iconv-go"
17+
goenc "github.com/mattn/go-encoding"
18+
// "golang.org/x/text/encoding"
19+
// "golang.org/x/text/transform"
1820
)
1921

2022
type reqError struct {
@@ -106,16 +108,18 @@ func proxy(resWriter http.ResponseWriter, reqHttp *http.Request) *reqError { //
106108
if prox.ConType.Type == "text" && prox.ConType.Subtype == "html" && prox.ConType.Parameters["charset"] != "" { // Does it say it's html with a valid charset
107109
resReader := strings.NewReader(string(prox.Body))
108110
if prox.ConType.Parameters["charset"] != "utf-8" {
109-
resIconvReader, err := iconv.NewReader(resReader, prox.ConType.Parameters["charset"], "utf-8")
110-
prox.Document, err = goquery.NewDocumentFromReader(resIconvReader) // Parse the response from our target website
111-
if err != nil { // Looks like we can't parse this, let's just spit out the raw response
111+
decoder := goenc.GetEncoding(prox.ConType.Parameters["charset"]).NewDecoder()
112+
prox.Document, err = goquery.NewDocumentFromReader(decoder.Reader(resReader)) // Parse the response from our target website
113+
if err != nil { // Looks like we can't parse this, let's just spit out the raw response
112114
fmt.Fprint(resWriter, string(prox.Body))
115+
fmt.Println(err.Error())
113116
return nil
114117
}
115118
} else {
116119
prox.Document, err = goquery.NewDocumentFromReader(resReader)
117120
if err != nil { // Looks like we can't parse this, let's just spit out the raw response
118121
fmt.Fprint(resWriter, string(prox.Body))
122+
fmt.Println(err.Error())
119123
return nil
120124
}
121125
}

0 commit comments

Comments
 (0)