Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcclient: add ExtraHeaders in ConnConfig #1669

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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