mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc: support dial http with context
This commit is contained in:
parent
4d663d57d6
commit
c38bdd3593
2 changed files with 5 additions and 6 deletions
|
|
@ -173,7 +173,7 @@ func DialContext(ctx context.Context, rawurl string) (*Client, error) {
|
|||
}
|
||||
switch u.Scheme {
|
||||
case "http", "https":
|
||||
return DialHTTP(rawurl)
|
||||
return DialHTTP(ctx, rawurl)
|
||||
case "ws", "wss":
|
||||
return DialWebsocket(ctx, rawurl, "")
|
||||
case "stdio":
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ var DefaultHTTPTimeouts = HTTPTimeouts{
|
|||
|
||||
// DialHTTPWithClient creates a new RPC client that connects to an RPC server over HTTP
|
||||
// using the provided HTTP Client.
|
||||
func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error) {
|
||||
func DialHTTPWithClient(ctx context.Context, endpoint string, client *http.Client) (*Client, error) {
|
||||
req, err := http.NewRequest(http.MethodPost, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -114,15 +114,14 @@ func DialHTTPWithClient(endpoint string, client *http.Client) (*Client, error) {
|
|||
req.Header.Set("Content-Type", contentType)
|
||||
req.Header.Set("Accept", contentType)
|
||||
|
||||
initctx := context.Background()
|
||||
return newClient(initctx, func(context.Context) (ServerCodec, error) {
|
||||
return newClient(ctx, func(context.Context) (ServerCodec, error) {
|
||||
return &httpConn{client: client, req: req, closeCh: make(chan interface{})}, nil
|
||||
})
|
||||
}
|
||||
|
||||
// DialHTTP creates a new RPC client that connects to an RPC server over HTTP.
|
||||
func DialHTTP(endpoint string) (*Client, error) {
|
||||
return DialHTTPWithClient(endpoint, new(http.Client))
|
||||
func DialHTTP(ctx context.Context, endpoint string) (*Client, error) {
|
||||
return DialHTTPWithClient(ctx, endpoint, new(http.Client))
|
||||
}
|
||||
|
||||
func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue