Allow Request.Context to be nil
This commit is contained in:
parent
a1dd8de337
commit
176b260468
@ -2,6 +2,7 @@ package gemini
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
@ -96,7 +97,12 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
|
|||||||
},
|
},
|
||||||
ServerName: hostname,
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ type Request struct {
|
|||||||
TLS tls.ConnectionState
|
TLS tls.ConnectionState
|
||||||
|
|
||||||
// Context specifies the context to use for client requests.
|
// 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
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,6 @@ func NewRequestFromURL(url *url.URL) *Request {
|
|||||||
return &Request{
|
return &Request{
|
||||||
URL: url,
|
URL: url,
|
||||||
Host: host,
|
Host: host,
|
||||||
Context: context.Background(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user