summaryrefslogtreecommitdiff
path: root/gemini
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-12 10:47:51 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-12 10:47:51 -0600
commit7d3cbefde656d5520067d56eeb44a8ba1f39d672 (patch)
treef8c12c0cc911cf24743798bbda6f3910f176db1a /gemini
parent23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 (diff)
multi-protocol client
Fixes #4
Diffstat (limited to 'gemini')
-rw-r--r--gemini/client.go10
-rw-r--r--gemini/response.go2
2 files changed, 8 insertions, 4 deletions
diff --git a/gemini/client.go b/gemini/client.go
index 34d5839..0a621dd 100644
--- a/gemini/client.go
+++ b/gemini/client.go
@@ -54,7 +54,7 @@ func (client Client) RoundTrip(request *types.Request) (*types.Response, error)
}
tlsConf := client.tlsConf
- if (tlsConf == nil) {
+ if tlsConf == nil {
tlsConf = &tls.Config{InsecureSkipVerify: true}
}
@@ -102,12 +102,12 @@ func (c Client) Fetch(url string) (*types.Response, error) {
if err != nil {
return nil, err
}
- if ResponseCategoryForStatus(response.Status) != ResponseCategoryRedirect {
+ if !c.IsRedirect(response) {
return response, nil
}
prev := u
- u, err = neturl.Parse(url)
+ u, err = neturl.Parse(response.Meta.(string))
if err != nil {
return nil, err
}
@@ -116,3 +116,7 @@ func (c Client) Fetch(url string) (*types.Response, error) {
return nil, ExceededMaxRedirects
}
+
+func (c Client) IsRedirect(response *types.Response) bool {
+ return ResponseCategoryForStatus(response.Status) == ResponseCategoryRedirect
+}
diff --git a/gemini/response.go b/gemini/response.go
index 13f493a..b3e53aa 100644
--- a/gemini/response.go
+++ b/gemini/response.go
@@ -44,7 +44,7 @@ const (
)
func ResponseCategoryForStatus(status types.Status) ResponseCategory {
- return ResponseCategory(status / 10)
+ return ResponseCategory((status / 10) * 10)
}
const (