From 19890c33cafbaede2bde55f11ca7539ae8a814a2 Mon Sep 17 00:00:00 2001 From: Robin Verton Date: Tue, 29 Sep 2020 13:14:45 +0200 Subject: [PATCH] Allow redirects from http to https on the same host, fixes #38 --- webanalyze.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webanalyze.go b/webanalyze.go index bf2a64d..07c56bd 100644 --- a/webanalyze.go +++ b/webanalyze.go @@ -61,7 +61,6 @@ func NewWebAnalyzer(apps io.Reader, client *http.Client) (*WebAnalyzer, error) { return nil, err } - wa.client = client return wa, nil @@ -108,7 +107,17 @@ func fetchHost(host string, client *http.Client) (*http.Response, error) { Proxy: http.ProxyFromEnvironment, }, CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse + url, err := url.Parse(host) + if err != nil { + return http.ErrUseLastResponse + } + + // allow redirects from http -> https on the same host + if url.Host != via[len(via)-1].URL.Host { + return http.ErrUseLastResponse + } + + return nil }, } }