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

Add support for custom/overriden HTTP headers when using JsonRpcProvider. #257

Closed
MicahZoltu opened this issue Aug 17, 2018 · 6 comments
Closed
Assignees
Labels
enhancement New feature or improvement.

Comments

@MicahZoltu
Copy link

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 a headers?: Map<string, string> key on the ConnectionInfo object that can be passed into JsonRpcProider 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.

@ricmoo
Copy link
Member

ricmoo commented Aug 17, 2018

Excellent idea!

@ricmoo ricmoo self-assigned this Aug 17, 2018
@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. v4.0 labels Aug 17, 2018
@MicahZoltu
Copy link
Author

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 ethers or building a new Ethereum node (both are large tasks).

@ricmoo
Copy link
Member

ricmoo commented Aug 18, 2018

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);
            })
        }
    }
}

@ricmoo
Copy link
Member

ricmoo commented Aug 18, 2018

Also, there seems to be something wrong with your backend if it is silently dropping so many connection. :p

@MicahZoltu
Copy link
Author

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

@ricmoo
Copy link
Member

ricmoo commented Sep 10, 2018

This is now available in 4.0.0-beta.14. The ConnectionInfo now supports headers which is a mapping of header keys and values as well as a timeout parameter.

Let me know if you have any issues with them.

Thanks! :)

@ricmoo ricmoo closed this as completed Sep 10, 2018
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement.
Projects
None yet
Development

No branches or pull requests

2 participants