Response header support added for Chrome Rendering
This commit is contained in:
parent
217f3c96df
commit
ec83a92eb3
@ -301,6 +301,7 @@ func (g *Geziyor) doRequestChrome(req *Request) (*Response, error) {
|
|||||||
Response: &http.Response{
|
Response: &http.Response{
|
||||||
Request: req.Request,
|
Request: req.Request,
|
||||||
StatusCode: int(res.Status),
|
StatusCode: int(res.Status),
|
||||||
|
Header: internal.ConvertMapToHeader(res.Headers),
|
||||||
},
|
},
|
||||||
Body: []byte(body),
|
Body: []byte(body),
|
||||||
Meta: req.Meta,
|
Meta: req.Meta,
|
||||||
|
@ -110,6 +110,7 @@ func TestGetRendered(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ParseFunc: func(g *geziyor.Geziyor, r *geziyor.Response) {
|
ParseFunc: func(g *geziyor.Geziyor, r *geziyor.Response) {
|
||||||
fmt.Println(string(r.Body))
|
fmt.Println(string(r.Body))
|
||||||
|
fmt.Println(r.Header)
|
||||||
},
|
},
|
||||||
//URLRevisitEnabled: true,
|
//URLRevisitEnabled: true,
|
||||||
}).Start()
|
}).Start()
|
||||||
|
@ -72,7 +72,7 @@ func SetDefaultHeader(header http.Header, key string, value string) http.Header
|
|||||||
return 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{} {
|
func ConvertHeaderToMap(header http.Header) map[string]interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
for key, values := range header {
|
for key, values := range header {
|
||||||
@ -82,3 +82,12 @@ func ConvertHeaderToMap(header http.Header) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
return m
|
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
|
||||||
|
}
|
||||||
|
@ -29,9 +29,6 @@ func (r *Response) JoinURL(relativeURL string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Response) isHTML() bool {
|
func (r *Response) isHTML() bool {
|
||||||
if r.Response == nil {
|
|
||||||
return len(r.Body) != 0
|
|
||||||
}
|
|
||||||
contentType := r.Header.Get("Content-Type")
|
contentType := r.Header.Get("Content-Type")
|
||||||
for _, htmlContentType := range []string{"text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml"} {
|
for _, htmlContentType := range []string{"text/html", "application/xhtml+xml", "application/vnd.wap.xhtml+xml"} {
|
||||||
if strings.Contains(contentType, htmlContentType) {
|
if strings.Contains(contentType, htmlContentType) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user