Skip to content

Commit

Permalink
rpcclient: add ExtraHeaders in ConnConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
10gic authored and jcvernaleo committed Nov 24, 2020
1 parent 0886f1e commit 610bb55
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rpcclient/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,9 @@ func (c *Client) sendPost(jReq *jsonRequest) {
}
httpReq.Close = true
httpReq.Header.Set("Content-Type", "application/json")
for key, value := range c.config.ExtraHeaders {
httpReq.Header.Set(key, value)
}

// Configure basic access authorization.
user, pass, err := c.config.getAuth()
Expand Down Expand Up @@ -1161,6 +1164,10 @@ type ConnConfig struct {
// flag can be set to true to use basic HTTP POST requests instead.
HTTPPostMode bool

// ExtraHeaders specifies the extra headers when perform request. It's
// useful when RPC provider need customized headers.
ExtraHeaders map[string]string

// EnableBCInfoHacks is an option provided to enable compatibility hacks
// when connecting to blockchain.info RPC server
EnableBCInfoHacks bool
Expand Down Expand Up @@ -1280,6 +1287,9 @@ func dial(config *ConnConfig) (*websocket.Conn, error) {
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
requestHeader := make(http.Header)
requestHeader.Add("Authorization", auth)
for key, value := range config.ExtraHeaders {
requestHeader.Add(key, value)
}

// Dial the connection.
url := fmt.Sprintf("%s://%s/%s", scheme, config.Host, config.Endpoint)
Expand Down

0 comments on commit 610bb55

Please sign in to comment.