summaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authortjp <tjp@ctrl-c.club>2024-01-10 11:07:48 -0700
committertjp <tjp@ctrl-c.club>2024-01-10 11:10:09 -0700
commitde1490808fa6e4d6749ff29d20cc1a589ec476d1 (patch)
tree301984b5005df669f8362d4843fab61472b5f125 /client.go
parentb2ff86d213128bb6f9ec9fa017ee4d566c77a397 (diff)
handle relative redirects
Diffstat (limited to 'client.go')
-rw-r--r--client.go8
1 files 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")
}