From de1490808fa6e4d6749ff29d20cc1a589ec476d1 Mon Sep 17 00:00:00 2001 From: tjp Date: Wed, 10 Jan 2024 11:07:48 -0700 Subject: handle relative redirects --- client.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 74fe04c..217a777 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/http" + "net/url" neturl "net/url" "tildegit.org/tjp/sliderule/finger" @@ -86,7 +87,7 @@ func (c Client) Fetch(url string) (*Response, error) { } prev := u - u, err = neturl.Parse(getRedirectLocation(u.Scheme, response.Meta)) + u, err = neturl.Parse(getRedirectLocation(prev, u.Scheme, response.Meta)) if err != nil { return nil, err } @@ -112,10 +113,11 @@ func (c Client) Upload(url string, contents io.Reader) (*Response, error) { } } -func getRedirectLocation(proto string, meta any) string { +func getRedirectLocation(prev *url.URL, proto string, meta any) string { switch proto { case "gemini", "spartan": - return meta.(string) + u, _ := url.Parse(meta.(string)) + return prev.ResolveReference(u).String() case "http", "https": return meta.(*http.Response).Header.Get("Location") } -- cgit v1.2.3