api: remove WithAuthorization, DirectAPI client, instantiate header map
This commit was moved from ipfs/go-ipfs-http-client@9c7d495b03db4d130a8fd87217093beb33e6fdb7
Alex committed
May 1, 2019 at 13:41 UTC
d8c286bb15e628dbe7ddd2370c77ef02a5dc16b2
1 file changed
+6
-26
client/httpapi/api.go
+6
-26
@@ -112,6 +112,7 @@ func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
112
api := &HttpApi{
113
url: url,
114
httpcli: *c,
115
+ Headers: make(map[string][]string),
116
applyGlobal: func(*RequestBuilder) {},
117
}
118
@@ -123,20 +124,11 @@ func NewApiWithClient(a ma.Multiaddr, c *gohttp.Client) (*HttpApi, error) {
124
return api, nil
125
}
126
126
-// NewDirectAPIClient is used to instantiate a HttpApi client
127
-// that connects to an endpoint which leverages additional http paths.
128
-//
129
-// If you need to connect to a IPFS HTTP API located at https://foo.bar/baz/api/v0
130
-// you should use NewDirectAPIClient.
131
-func NewDirectAPIClient(url string) (*HttpApi, error) {
127
+func NewURLApiWithClient(url string, c *gohttp.Client) (*HttpApi, error) {
128
api := &HttpApi{
133
- url: url,
134
- httpcli: gohttp.Client{
135
- Transport: &gohttp.Transport{
136
- Proxy: gohttp.ProxyFromEnvironment,
137
- DisableKeepAlives: true,
138
- },
139
- },
129
+ url: url,
130
+ httpcli: *c,
131
+ Headers: make(map[string][]string),
132
applyGlobal: func(*RequestBuilder) {},
133
}
134
@@ -144,21 +136,9 @@ func NewDirectAPIClient(url string) (*HttpApi, error) {
136
api.httpcli.CheckRedirect = func(_ *gohttp.Request, _ []*gohttp.Request) error {
137
return fmt.Errorf("unexpected redirect")
138
}
147
-
139
return api, nil
140
}
141
151
-// WithAuthorization is used to wrap an instance of HttpApi
152
-// with an authenticated transport, such as JWT
153
-func (api *HttpApi) WithAuthorization(header, value string) *HttpApi {
154
- return &HttpApi{
155
- url: api.url,
156
- httpcli: gohttp.Client{
157
- Transport: newAuthenticatedTransport(api.httpcli.Transport, header, value),
158
- },
159
- }
160
-}
161
-
142
func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error) {
143
options, err := caopts.ApiOptions(opts...)
144
if err != nil {
@@ -176,7 +156,7 @@ func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error)
156
}
157
158
func (api *HttpApi) Request(command string, args ...string) *RequestBuilder {
179
- var headers map[string]string
159
+ headers := make(map[string]string)
160
if api.Headers != nil {
161
for k := range api.Headers {
162
headers[k] = api.Headers.Get(k)