-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add support for custom/overriden HTTP headers when using JsonRpcProvider. #257
Comments
Excellent idea! |
I can create a separate ticket, but at the same time it would be nice to be able to provide other connection options. I am having a problem right now where a backend node I'm talking to is silently dropping my connections sometimes. The default timeout for the underlying connection in ethers is 2 minutes it appears, but if it has been more than 2 second I want a timeout propagated. The frequency of this connection dropping combined with the 2 minute timeout before I hear about it makes me have to choose between dropping |
It is trivial to implement a Customer Provider if you want a 2s timeout. This is off the top of my head, but you will get the idea. class ShortTimeoutProvider extends ethers.types.Provider {
readonly provider: ethers.types.Provider;
constructor(provider: ethers.types.Provider) {
this.provider = provider;
}
perform(method, params): Promise<any> {
return new Promise((resolve, reject) => {
setTimeout(() => { reject('over 2 seconds!'); }, 2000);
provider.perform(method, params).then((result) => {
resolve(result);
},
(error) => {
reject(error);
})
}
}
} |
Also, there seems to be something wrong with your backend if it is silently dropping so many connection. :p |
Yeah, something is wrong with my connection but I can't figure out what it is. Thanks for the workaround suggestion, that should buy me time to solve the real problem. :) Related in adding timeout makes the roadmap: driverdan/node-XMLHttpRequest#148 |
This is now available in 4.0.0-beta.14. The ConnectionInfo now supports Let me know if you have any issues with them. Thanks! :) |
I would like to use the
JsonRpcProvider
, but my node is behind a firewall that needs me to add some custom headers to route through. I would like the ability to provide arbitrary headers along with all payloads. Ideally, there would be aheaders?: Map<string, string>
key on theConnectionInfo
object that can be passed intoJsonRpcProider
constructor. This way I could specify any headers needed to access the backing node. This would also address another user's request for Bearer token authentication support, as they could provide that header through this mechanism.The text was updated successfully, but these errors were encountered: