summaryrefslogtreecommitdiff
path: root/nex/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'nex/client.go')
-rw-r--r--nex/client.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/nex/client.go b/nex/client.go
index 4a34903..4fa5265 100644
--- a/nex/client.go
+++ b/nex/client.go
@@ -2,6 +2,7 @@ package nex
import (
"bytes"
+ "context"
"errors"
"io"
"net"
@@ -18,7 +19,7 @@ import (
type Client struct{}
// RoundTrip sends a single nex 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 != "nex" && request.Scheme != "" {
return nil, errors.New("non-nex protocols not supported")
}
@@ -28,7 +29,7 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) {
host = net.JoinHostPort(host, "1900")
}
- conn, err := net.Dial("tcp", host)
+ conn, err := (&net.Dialer{}).DialContext(ctx, "tcp", host)
if err != nil {
return nil, err
}
@@ -50,12 +51,12 @@ func (c Client) RoundTrip(request *types.Request) (*types.Response, error) {
}
// Fetch builds and sends a nex request, and returns the response.
-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(response *types.Response) bool { return false }