JoinURL deprecated
This commit is contained in:
parent
019fe62883
commit
b8bda36f92
@ -22,12 +22,15 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// JoinURL joins base response URL and provided relative URL.
|
// JoinURL joins base response URL and provided relative URL.
|
||||||
func (r *Response) JoinURL(relativeURL string) (*url.URL, error) {
|
// DEPRECATED: Use response.Request.URL.Parse(relativeURL) instead.
|
||||||
joinedURL, err := r.Request.URL.Parse(relativeURL)
|
func (r *Response) JoinURL(relativeURL string) string {
|
||||||
|
parsedRelativeURL, err := url.Parse(relativeURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return ""
|
||||||
}
|
}
|
||||||
return joinedURL, nil
|
|
||||||
|
joinedURL := r.Request.URL.ResolveReference(parsedRelativeURL)
|
||||||
|
return joinedURL.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsHTML checks if response content is HTML by looking content-type header
|
// IsHTML checks if response content is HTML by looking content-type header
|
||||||
|
@ -9,7 +9,6 @@ func TestResponse_JoinURL(t *testing.T) {
|
|||||||
req, _ := NewRequest("GET", "https://localhost.com/test/a.html", nil)
|
req, _ := NewRequest("GET", "https://localhost.com/test/a.html", nil)
|
||||||
resp := Response{Request: req}
|
resp := Response{Request: req}
|
||||||
|
|
||||||
joinedURL, err := resp.JoinURL("/source")
|
joinedURL := resp.JoinURL("/source")
|
||||||
assert.NoError(t, err)
|
assert.Equal(t, "https://localhost.com/source", joinedURL)
|
||||||
assert.Equal(t, "https://localhost.com/source", joinedURL.String())
|
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func quotesParse(g *geziyor.Geziyor, r *client.Response) {
|
|||||||
|
|
||||||
// Next Page
|
// Next Page
|
||||||
if href, ok := r.HTMLDoc.Find("li.next > a").Attr("href"); ok {
|
if href, ok := r.HTMLDoc.Find("li.next > a").Attr("href"); ok {
|
||||||
absoluteURL, _ := r.JoinURL(href)
|
absoluteURL, _ := r.Request.URL.Parse(href)
|
||||||
g.Get(absoluteURL.String(), quotesParse)
|
g.Get(absoluteURL.String(), quotesParse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ func TestAllLinks(t *testing.T) {
|
|||||||
g.Exports <- []string{r.Request.URL.String()}
|
g.Exports <- []string{r.Request.URL.String()}
|
||||||
r.HTMLDoc.Find("a").Each(func(i int, s *goquery.Selection) {
|
r.HTMLDoc.Find("a").Each(func(i int, s *goquery.Selection) {
|
||||||
if href, ok := s.Attr("href"); ok {
|
if href, ok := s.Attr("href"); ok {
|
||||||
absoluteURL, _ := r.JoinURL(href)
|
absoluteURL, _ := r.Request.URL.Parse(href)
|
||||||
g.Get(absoluteURL.String(), g.Opt.ParseFunc)
|
g.Get(absoluteURL.String(), g.Opt.ParseFunc)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -333,7 +333,7 @@ func BenchmarkWhole(b *testing.B) {
|
|||||||
g.Exports <- []string{r.Request.URL.String()}
|
g.Exports <- []string{r.Request.URL.String()}
|
||||||
r.HTMLDoc.Find("a").Each(func(i int, s *goquery.Selection) {
|
r.HTMLDoc.Find("a").Each(func(i int, s *goquery.Selection) {
|
||||||
if href, ok := s.Attr("href"); ok {
|
if href, ok := s.Attr("href"); ok {
|
||||||
absoluteURL, _ := r.JoinURL(href)
|
absoluteURL, _ := r.Request.URL.Parse(href)
|
||||||
g.Get(absoluteURL.String(), g.Opt.ParseFunc)
|
g.Get(absoluteURL.String(), g.Opt.ParseFunc)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user