@@ -45,17 +45,23 @@ func (c *Client) SetHTTPProxyURL(proxyURL *url.URL) {
45
45
c .httpClient .Transport .(* http.Transport ).Proxy = http .ProxyURL (proxyURL )
46
46
}
47
47
48
+ // RunOptions represents options that can be used to configure a Run
49
+ // operation.
50
+ type RunOptions struct {
51
+ AdditionalHeaders map [string ]string
52
+ }
53
+
48
54
// Run executes the given method having the given params setting the response
49
55
// value in the given result interface.
50
- func (c * Client ) Run (method string , params interface {}, result interface {}) error {
56
+ func (c * Client ) Run (method string , params interface {}, result interface {}, opts ... RunOptions ) error {
51
57
request := NewRequest (method , params , RandInt (10000000 , 99999999 ))
52
58
53
59
jsonRequest , err := json .Marshal (request )
54
60
if err != nil {
55
61
return err
56
62
}
57
63
58
- jsonResponse , err := c .sendJSONRequest (jsonRequest )
64
+ jsonResponse , err := c .sendJSONRequest (jsonRequest , opts ... )
59
65
if err != nil {
60
66
return err
61
67
}
@@ -75,25 +81,29 @@ func (c *Client) Run(method string, params interface{}, result interface{}) erro
75
81
return nil
76
82
}
77
83
84
+ // NotifyOptions represents options that can be used to configure a Notify
85
+ // operation.
86
+ type NotifyOptions = RunOptions
87
+
78
88
// Notify executes the given method with the given parameters.
79
89
// Doesn't expect any result.
80
- func (c * Client ) Notify (method string , params interface {}) error {
90
+ func (c * Client ) Notify (method string , params interface {}, opts ... NotifyOptions ) error {
81
91
request := NewRequest (method , params , 0 )
82
92
83
93
jsonRequest , err := json .Marshal (request )
84
94
if err != nil {
85
95
return err
86
96
}
87
97
88
- _ , err = c .sendJSONRequest (jsonRequest )
98
+ _ , err = c .sendJSONRequest (jsonRequest , opts ... )
89
99
if err != nil {
90
100
return err
91
101
}
92
102
93
103
return nil
94
104
}
95
105
96
- func (c * Client ) sendJSONRequest (jsonRequest []byte ) ([]byte , error ) {
106
+ func (c * Client ) sendJSONRequest (jsonRequest []byte , opts ... RunOptions ) ([]byte , error ) {
97
107
var jsonResponse []byte
98
108
99
109
httpRequest , err := http .NewRequest ("POST" , c .serverURL , strings .NewReader (string (jsonRequest )))
@@ -102,6 +112,13 @@ func (c *Client) sendJSONRequest(jsonRequest []byte) ([]byte, error) {
102
112
httpRequest .Header .Set ("Accept" , "application/json" )
103
113
httpRequest .Header .Set ("Connection" , "close" )
104
114
115
+ // Apply additional headers
116
+ for _ , o := range opts {
117
+ for key , value := range o .AdditionalHeaders {
118
+ httpRequest .Header .Set (key , value )
119
+ }
120
+ }
121
+
105
122
httpResponse , err := c .httpClient .Do (httpRequest )
106
123
if err != nil {
107
124
return jsonResponse , err
0 commit comments