From 7d3cbefde656d5520067d56eeb44a8ba1f39d672 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Sat, 12 Aug 2023 10:47:51 -0600 Subject: multi-protocol client Fixes #4 --- gemini/client.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'gemini/client.go') 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 +} -- cgit v1.2.3