@cryptotaxi247 / kubo / commits / 11a990c7b

api: expose headers via HttpApi, copy headers during request build

This commit was moved from ipfs/go-ipfs-http-client@033befdef3f06a4a80fb9cf7c3afecc1a383700c

Alex committed May 1, 2019 at 13:13 UTC 11a990c7b12db59d9d03cbd9b28c2b8c75abfa26
1 file changed +11 -3
client/httpapi/api.go
+11 -3
@@ -4,6 +4,7 @@ import (
4 "errors"
5 "fmt"
6 "io/ioutil"
7 + "net/http"
8 gohttp "net/http"
9 "os"
10 "path"
@@ -32,9 +33,9 @@ var ErrApiNotFound = errors.New("ipfs api address could not be found")
33 // For interface docs see
34 // https://godoc.org/github.com/ipfs/interface-go-ipfs-core#CoreAPI
35 type HttpApi struct {
35 - url string
36 - httpcli gohttp.Client
37 -
36 + url string
37 + httpcli gohttp.Client
38 + Headers http.Header
39 applyGlobal func(*RequestBuilder)
40 }
41
@@ -175,10 +176,17 @@ func (api *HttpApi) WithOptions(opts ...caopts.ApiOption) (iface.CoreAPI, error)
176 }
177
178 func (api *HttpApi) Request(command string, args ...string) *RequestBuilder {
179 + var headers map[string]string
180 + if api.Headers != nil {
181 + for k := range api.Headers {
182 + headers[k] = api.Headers.Get(k)
183 + }
184 + }
185 return &RequestBuilder{
186 command: command,
187 args: args,
188 shell: api,
189 + headers: headers,
190 }
191 }
192