summaryrefslogtreecommitdiff
path: root/gopher/client.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-12 08:48:09 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-12 08:48:09 -0600
commit330b6e4828d59a6d5fae3cc7a30e6fda0856577b (patch)
tree543e36f992fb736f0a32b871ebc3e8a309ef2d5e /gopher/client.go
parenteee03adc1b4ed1545da059613c4cff12b14d6306 (diff)
add Fetch method to clients which follows redirects
There are currently only gopher, gemini, and spartan clients. The finger client will have to implement this when it is written. The Fetch method takes the url as a string for convenience, and parses it into a URL for RoundTrip. Fixes #3
Diffstat (limited to 'gopher/client.go')
-rw-r--r--gopher/client.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/gopher/client.go b/gopher/client.go
index fad9413..163d0cd 100644
--- a/gopher/client.go
+++ b/gopher/client.go
@@ -5,6 +5,7 @@ import (
"errors"
"io"
"net"
+ neturl "net/url"
sr "tildegit.org/tjp/sliderule"
)
@@ -53,3 +54,12 @@ func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) {
return &sr.Response{Body: bytes.NewBuffer(response)}, nil
}
+
+// Fetch parses a URL string and fetches the gopher resource.
+func (c Client) Fetch(url string) (*sr.Response, error) {
+ u, err := neturl.Parse(url)
+ if err != nil {
+ return nil, err
+ }
+ return c.RoundTrip(&sr.Request{URL: u})
+}