Fix host parsing

This commit is contained in:
y a t s
2025-01-30 20:12:19 -05:00
parent 46634a9ea1
commit f7c8794849

View File

@@ -32,6 +32,18 @@ func NewKF(hc http.Client, host string, cookies string) (kf *KF, err error) {
domain: u,
}
// Update host url in case we get redirected across domains.
hc.CheckRedirect = func(req *http.Request, via []*http.Request) error {
hn := req.URL.Hostname()
if hn != u.Hostname() {
// Deliberately set to Hostname() and not Host.
// This excludes any extra shit like ports.
u.Host = hn
}
return nil
}
return
}
@@ -101,7 +113,7 @@ func (kf *KF) solveKiwiFlare(ctx context.Context) error {
func parseHost(host string) (*url.URL, error) {
// Try prepending protocol if it seems to be missing.
if !strings.Contains(strings.Split(host, "/")[0], "://") {
if !strings.Contains(host, "://") {
host = "https://" + host
}