diff --git a/client.go b/client.go index 21a5c4f..6821ded 100644 --- a/client.go +++ b/client.go @@ -2,6 +2,7 @@ package gemini import ( "bufio" + "context" "crypto/tls" "crypto/x509" "errors" @@ -96,7 +97,12 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) { }, ServerName: hostname, } - netConn, err := (&net.Dialer{}).DialContext(req.Context, "tcp", req.Host) + + ctx := req.Context + if ctx == nil { + ctx = context.Background() + } + netConn, err := (&net.Dialer{}).DialContext(ctx, "tcp", req.Host) if err != nil { return nil, err } diff --git a/request.go b/request.go index b4c95c2..138fc15 100644 --- a/request.go +++ b/request.go @@ -36,7 +36,7 @@ type Request struct { TLS tls.ConnectionState // Context specifies the context to use for client requests. - // Context must not be nil. + // If Context is nil, the background context will be used. Context context.Context } @@ -60,9 +60,8 @@ func NewRequestFromURL(url *url.URL) *Request { host += ":1965" } return &Request{ - URL: url, - Host: host, - Context: context.Background(), + URL: url, + Host: host, } }