diff --git a/geziyor.go b/geziyor.go index 2c2424b..94ee138 100644 --- a/geziyor.go +++ b/geziyor.go @@ -301,6 +301,7 @@ func (g *Geziyor) doRequestChrome(req *Request) (*Response, error) { Response: &http.Response{ Request: req.Request, StatusCode: int(res.Status), + Header: internal.ConvertMapToHeader(res.Headers), }, Body: []byte(body), Meta: req.Meta, diff --git a/geziyor_test.go b/geziyor_test.go index 44a1dfc..0c5ff29 100644 --- a/geziyor_test.go +++ b/geziyor_test.go @@ -110,6 +110,7 @@ func TestGetRendered(t *testing.T) { }, ParseFunc: func(g *geziyor.Geziyor, r *geziyor.Response) { fmt.Println(string(r.Body)) + fmt.Println(r.Header) }, //URLRevisitEnabled: true, }).Start() diff --git a/internal/http.go b/internal/http.go index 5500940..5fe50cd 100644 --- a/internal/http.go +++ b/internal/http.go @@ -72,7 +72,7 @@ func SetDefaultHeader(header http.Header, key string, value string) http.Header return header } -// CovertHeaderToMap converts http.Header to map[string]interface{} +// ConvertHeaderToMap converts http.Header to map[string]interface{} func ConvertHeaderToMap(header http.Header) map[string]interface{} { m := make(map[string]interface{}) for key, values := range header { @@ -82,3 +82,12 @@ func ConvertHeaderToMap(header http.Header) map[string]interface{} { } return m } + +// ConvertMapToHeader converts map[string]interface{} to http.Header +func ConvertMapToHeader(m map[string]interface{}) http.Header { + header := make(map[string][]string) + for k, v := range m { + header[k] = []string{v.(string)} + } + return header +} diff --git a/response.go b/response.go index 1aa3ed3..861c934 100644 --- a/response.go +++ b/response.go @@ -29,9 +29,6 @@ func (r *Response) JoinURL(relativeURL string) string { } func (r *Response) isHTML() bool { - if r.Response == nil { - return len(r.Body) != 0 - } contentType := r.Header.Get("Content-Type") for _, htmlContentType := range []string{"text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml"} { if strings.Contains(contentType, htmlContentType) {