Skip to content

rpc: Support specifying HTTP client in RPC dialing#15836

Merged
karalabe merged 2 commits into
ethereum:masterfrom
stevenroose:http-client
Jan 24, 2018
Merged

rpc: Support specifying HTTP client in RPC dialing#15836
karalabe merged 2 commits into
ethereum:masterfrom
stevenroose:http-client

Conversation

@stevenroose
Copy link
Copy Markdown
Contributor

Adds a minimal interface that captures http.Client and adds a new method rpc.DialHTTPClient that takes a client using that interface. The existing rpc.DialHTTP method is then alternatively implemented by using the new rpc.DialHTTPClient method provided with a standard *http.Client.

Comment thread rpc/http.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo 'contaisn'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, thanks. Fixed it.

@stevenroose stevenroose force-pushed the http-client branch 2 times, most recently from 0daaabf to 3eea7f9 Compare January 23, 2018 11:25
@stevenroose
Copy link
Copy Markdown
Contributor Author

ping..

Comment thread rpc/http.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to define this interface here, as any eventual extra method (that's provided by Go's http.Client) will result in breaking the interface. Let's just directly require specifying a *http.Client. That way we're future proof.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah had that first, but it makes it impossible to use wrappers of an http.Client like proxies or monitors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK that's what http.Client.Transport is for:

    // Transport specifies the mechanism by which individual
    // HTTP requests are made.
    // If nil, DefaultTransport is used.
    Transport RoundTripper

You can define all proxy and monitoring methods inside the http Client and that's how other libraries use it too (e.g. Google's Go APIs googleapis/google-api-go-client#146 (comment)).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, didn't know about the Transport field. That's a smart thing they did there. Will change, one sec.

Comment thread rpc/http.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usual "way" in Go code when initializing something with an extra parameter is With. I.e. DialHTTPWithClient. Please rename.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense.

Copy link
Copy Markdown
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally ok, just a couple minor issues.

@karalabe karalabe added this to the 1.8.0 milestone Jan 23, 2018
Adds a minimal interface that captures http.Client and adds a new method
rpc.DialHTTPClient that takes a client using that interface. The existing
rpc.DialHTTP method is then alternatively implemented by using the new
rpc.DialHTTPClient method provided with a standard *http.Client.
Copy link
Copy Markdown
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@karalabe karalabe merged commit 952482d into ethereum:master Jan 24, 2018
prestonvanloon pushed a commit to prestonvanloon/go-ethereum that referenced this pull request Apr 2, 2018
* rpc: Support specifying HTTP client in RPC dialing

Adds a minimal interface that captures http.Client and adds a new method
rpc.DialHTTPClient that takes a client using that interface. The existing
rpc.DialHTTP method is then alternatively implemented by using the new
rpc.DialHTTPClient method provided with a standard *http.Client.

* rpc: fix minor doc typos
mariameda pushed a commit to NiluPlatform/go-nilu that referenced this pull request Aug 23, 2018
* rpc: Support specifying HTTP client in RPC dialing

Adds a minimal interface that captures http.Client and adds a new method
rpc.DialHTTPClient that takes a client using that interface. The existing
rpc.DialHTTP method is then alternatively implemented by using the new
rpc.DialHTTPClient method provided with a standard *http.Client.

* rpc: fix minor doc typos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants