diff options
author | tjp <tjp@ctrl-c.club> | 2024-01-13 11:29:17 -0700 |
---|---|---|
committer | tjp <tjp@ctrl-c.club> | 2024-01-13 11:29:17 -0700 |
commit | 4d861a2c395c0926b066014b92999d4dda454b2b (patch) | |
tree | 7bbf7d94cec2a5412a68b830c1e5223918d9bc82 /gopher | |
parent | de1490808fa6e4d6749ff29d20cc1a589ec476d1 (diff) |
dial timeouts for clients, and catch up on test fixes
Diffstat (limited to 'gopher')
-rw-r--r-- | gopher/client.go | 9 | ||||
-rw-r--r-- | gopher/gophermap/testdata/customlist_output.gophermap | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/gopher/client.go b/gopher/client.go index 0ae1730..6d46323 100644 --- a/gopher/client.go +++ b/gopher/client.go @@ -2,6 +2,7 @@ package gopher import ( "bytes" + "context" "errors" "io" "net" @@ -18,7 +19,7 @@ import ( type Client struct{} // RoundTrip sends a single gopher request and returns its response. -func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { +func (c Client) RoundTrip(ctx context.Context, request *types.Request) (*types.Response, error) { if request.Scheme != "gopher" && request.Scheme != "" { return nil, errors.New("non-gopher protocols not supported") } @@ -28,7 +29,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { host = net.JoinHostPort(host, "70") } - conn, err := net.Dial("tcp", host) + conn, err := (&net.Dialer{}).DialContext(ctx, "tcp", host) if err != nil { return nil, err } @@ -56,12 +57,12 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) { } // Fetch parses a URL string and fetches the gopher resource. -func (c Client) Fetch(url string) (*types.Response, error) { +func (c Client) Fetch(ctx context.Context, url string) (*types.Response, error) { u, err := neturl.Parse(url) if err != nil { return nil, err } - return c.RoundTrip(&types.Request{URL: u}) + return c.RoundTrip(ctx, &types.Request{URL: u}) } func (c Client) IsRedirect(_ *types.Response) bool { return false } diff --git a/gopher/gophermap/testdata/customlist_output.gophermap b/gopher/gophermap/testdata/customlist_output.gophermap index 0b4e334..82330e0 100644 --- a/gopher/gophermap/testdata/customlist_output.gophermap +++ b/gopher/gophermap/testdata/customlist_output.gophermap @@ -11,6 +11,6 @@ i /customlist.gophermap localhost.localdomain 70 0file4.txt /file4.txt localhost.localdomain 70
1subdir title /subdir localhost.localdomain 70
1subdir2 title /subdir2 localhost.localdomain 70
-9uptime /uptime localhost.localdomain 70
+0uptime /uptime localhost.localdomain 70
1uptime_output.gophermap /uptime_output.gophermap localhost.localdomain 70
.
|