diff options
| author | Adnan Maolood <[email protected]> | 2020-12-17 17:16:55 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-12-17 17:16:55 -0500 |
| commit | 176b260468e9d586d79b55d853289bc3e87785dd (patch) | |
| tree | de2f130723e92d0ce9b6efc2a0625d7faaa67105 | |
| parent | Fix locking up of KnownHostsFile and CertificateDir (diff) | |
| download | go-gemini-176b260468e9d586d79b55d853289bc3e87785dd.tar.xz go-gemini-176b260468e9d586d79b55d853289bc3e87785dd.zip | |
Allow Request.Context to be nil
| -rw-r--r-- | client.go | 8 | ||||
| -rw-r--r-- | request.go | 7 |
2 files changed, 10 insertions, 5 deletions
@@ -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 } @@ -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, } } |