JoinURL deprecated

This commit is contained in:
Musab Gültekin
2021-10-05 22:13:00 +03:00
parent 019fe62883
commit b8bda36f92
3 changed files with 12 additions and 10 deletions

View File

@ -22,12 +22,15 @@ type Response struct {
}
// JoinURL joins base response URL and provided relative URL.
func (r *Response) JoinURL(relativeURL string) (*url.URL, error) {
joinedURL, err := r.Request.URL.Parse(relativeURL)
// DEPRECATED: Use response.Request.URL.Parse(relativeURL) instead.
func (r *Response) JoinURL(relativeURL string) string {
parsedRelativeURL, err := url.Parse(relativeURL)
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

View File

@ -9,7 +9,6 @@ func TestResponse_JoinURL(t *testing.T) {
req, _ := NewRequest("GET", "https://localhost.com/test/a.html", nil)
resp := Response{Request: req}
joinedURL, err := resp.JoinURL("/source")
assert.NoError(t, err)
assert.Equal(t, "https://localhost.com/source", joinedURL.String())
joinedURL := resp.JoinURL("/source")
assert.Equal(t, "https://localhost.com/source", joinedURL)
}