This commit is contained in:
Administrator
2024-09-05 18:16:17 +08:00
parent 688c516c9f
commit 88f37ecc2d
9 changed files with 170 additions and 26 deletions

View File

@ -2,6 +2,7 @@ package client
import (
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
"net/http"
"net/url"
"strings"
@ -18,6 +19,9 @@ type Response struct {
// Goquery Document object. If response IsHTML, its non-nil.
HTMLDoc *goquery.Document
// xpath Document object. If response IsHTML, its non-nil.
HTMLNode *html.Node
Request *Request
}
@ -33,6 +37,15 @@ func (r *Response) JoinURL(relativeURL string) string {
return joinedURL.String()
}
// JoinURL2 joins base response URL and provided relative URL.
func (r *Response) JoinURL2(relativeURL string) string {
joinedURL, err := r.Request.URL.Parse(relativeURL)
if err != nil {
return ""
}
return joinedURL.String()
}
// IsHTML checks if response content is HTML by looking content-type header
func (r *Response) IsHTML() bool {
contentType := r.Header.Get("Content-Type")