From 610bb55ae85ccbc73958f44df1fba0ba888559ce Mon Sep 17 00:00:00 2001 From: 10gic <2391796+10gic@users.noreply.github.com> Date: Fri, 20 Nov 2020 17:58:10 +0800 Subject: [PATCH] rpcclient: add ExtraHeaders in ConnConfig --- rpcclient/infrastructure.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index 8609e7c5ad..4f15ed1430 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -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() @@ -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 @@ -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)