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

Make HTTPProvider.get_request_headers() a class-level method #3466

Closed
antazoey opened this issue Aug 28, 2024 · 3 comments · Fixed by #3467
Closed

Make HTTPProvider.get_request_headers() a class-level method #3466

antazoey opened this issue Aug 28, 2024 · 3 comments · Fixed by #3467

Comments

@antazoey
Copy link
Contributor

What feature should we add?

At the time of writing this issue, the method is defined here:
https://github.com/ethereum/web3.py/blob/main/web3/providers/rpc/rpc.py#L119-L123

It is:

    def get_request_headers(self) -> Dict[str, str]:
        return {
            "Content-Type": "application/json",
            "User-Agent": construct_user_agent(str(type(self))),
        }

I am requesting this method be exposed at the class-level, to be re-written as:

    @classmethod
    def get_request_headers(cls) -> Dict[str, str]:
        return {
            "Content-Type": "application/json",
            "User-Agent": construct_user_agent(str(cls)),
        }

Use-case: This allows me to grab the default headers before constructing an HTTPProvider object for the purpose of modifying them / appending to them, without having to redefine.

@kclowes
Copy link
Collaborator

kclowes commented Aug 28, 2024

Yep, we can do that!

@fselmo
Copy link
Collaborator

fselmo commented Aug 29, 2024

@antazoey this was just released in web3.py v7.2.0 in case you need to reach for it.

@antazoey
Copy link
Contributor Author

@antazoey this was just released in web3.py v7.2.0 in case you need to reach for it.

Thanks, for reasons of my own doing, we are not able to officially update web3.py until Ape's 0.9 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants