Response header support added for Chrome Rendering

This commit is contained in:
Musab Gültekin 2019-06-18 16:26:40 +03:00
parent 217f3c96df
commit ec83a92eb3
4 changed files with 12 additions and 4 deletions

View File

@ -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,

View File

@ -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()

View File

@ -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
}

View File

@ -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) {