Skip to content

Commit 3b171a2

Browse files
committed
http: allow specifying a custom http client
fixes ipfs#174
1 parent 6b2c4ae commit 3b171a2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-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

0 commit comments

Comments
 (0)