@@ -44,18 +44,22 @@ type rpcRequest struct {
44
44
45
45
// FlashbotsRPC - Ethereum rpc client
46
46
type FlashbotsRPC struct {
47
- url string
48
- client httpClient
49
- log logger
50
- Debug bool
47
+ url string
48
+ client httpClient
49
+ log logger
50
+ Debug bool
51
+ Headers map [string ]string // Additional headers to send with the request
52
+ Timeout time.Duration
51
53
}
52
54
53
55
// New create new rpc client with given url
54
56
func New (url string , options ... func (rpc * FlashbotsRPC )) * FlashbotsRPC {
55
57
rpc := & FlashbotsRPC {
56
- url : url ,
57
- client : http .DefaultClient ,
58
- log : log .New (os .Stderr , "" , log .LstdFlags ),
58
+ url : url ,
59
+ client : http .DefaultClient ,
60
+ log : log .New (os .Stderr , "" , log .LstdFlags ),
61
+ Headers : make (map [string ]string ),
62
+ Timeout : 30 * time .Second ,
59
63
}
60
64
for _ , option := range options {
61
65
option (rpc )
@@ -101,7 +105,21 @@ func (rpc *FlashbotsRPC) Call(method string, params ...interface{}) (json.RawMes
101
105
return nil , err
102
106
}
103
107
104
- response , err := rpc .client .Post (rpc .url , "application/json" , bytes .NewBuffer (body ))
108
+ req , err := http .NewRequest ("POST" , rpc .url , bytes .NewBuffer (body ))
109
+ if err != nil {
110
+ return nil , err
111
+ }
112
+
113
+ req .Header .Add ("Content-Type" , "application/json" )
114
+ req .Header .Add ("Accept" , "application/json" )
115
+ for k , v := range rpc .Headers {
116
+ req .Header .Add (k , v )
117
+ }
118
+ httpClient := & http.Client {
119
+ Timeout : rpc .Timeout ,
120
+ }
121
+
122
+ response , err := httpClient .Do (req )
105
123
if response != nil {
106
124
defer response .Body .Close ()
107
125
}
@@ -160,8 +178,11 @@ func (rpc *FlashbotsRPC) CallWithFlashbotsSignature(method string, privKey *ecds
160
178
req .Header .Add ("Content-Type" , "application/json" )
161
179
req .Header .Add ("Accept" , "application/json" )
162
180
req .Header .Add ("X-Flashbots-Signature" , signature )
181
+ for k , v := range rpc .Headers {
182
+ req .Header .Add (k , v )
183
+ }
163
184
httpClient := & http.Client {
164
- Timeout : time . Second * 30 ,
185
+ Timeout : rpc . Timeout ,
165
186
}
166
187
167
188
response , err := httpClient .Do (req )
0 commit comments