Skip to content

Commit 1d203a2

Browse files
authored
Merge pull request #175 from ipfs/fix/174
http: allow specifying a custom http client
2 parents ba86293 + 3b171a2 commit 1d203a2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

http/client.go

+12
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,25 @@ type client struct {
3030
fallback cmds.Executor
3131
}
3232

33+
// ClientOpt is an option that can be passed to the HTTP client constructor.
3334
type ClientOpt func(*client)
3435

36+
// ClientWithUserAgent specifies the HTTP user agent for the client.
3537
func ClientWithUserAgent(ua string) ClientOpt {
3638
return func(c *client) {
3739
c.ua = ua
3840
}
3941
}
4042

43+
// ClientWithHTTPClient specifies a custom http.Client. Defaults to
44+
// http.DefaultClient.
45+
func ClientWithHTTPClient(hc *http.Client) ClientOpt {
46+
return func(c *client) {
47+
c.httpClient = hc
48+
}
49+
}
50+
51+
// ClientWithAPIPrefix specifies an API URL prefix.
4152
func ClientWithAPIPrefix(apiPrefix string) ClientOpt {
4253
return func(c *client) {
4354
c.apiPrefix = apiPrefix
@@ -53,6 +64,7 @@ func ClientWithFallback(exe cmds.Executor) ClientOpt {
5364
}
5465
}
5566

67+
// NewClient constructs a new HTTP-backed command executor.
5668
func NewClient(address string, opts ...ClientOpt) cmds.Executor {
5769
if !strings.HasPrefix(address, "http://") {
5870
address = "http://" + address

http/executor_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package http

0 commit comments

Comments
 (0)