From f7c879484942a49635c33ed0f08677d00c0dc2a1 Mon Sep 17 00:00:00 2001 From: y a t s <140337963+y-a-t-s@users.noreply.github.com> Date: Thu, 30 Jan 2025 20:12:19 -0500 Subject: [PATCH] Fix host parsing --- libkiwi.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libkiwi.go b/libkiwi.go index 91bd63c..0eac4ed 100644 --- a/libkiwi.go +++ b/libkiwi.go @@ -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 }