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

feat(cast): add ability to specify request headers #9422

Closed
2 tasks
sebastiendan opened this issue Nov 27, 2024 · 6 comments · Fixed by #9429
Closed
2 tasks

feat(cast): add ability to specify request headers #9422

sebastiendan opened this issue Nov 27, 2024 · 6 comments · Fixed by #9429
Assignees
Labels
C-cast Command: cast first issue A good way to start contributing T-feature Type: feature

Comments

@sebastiendan
Copy link

Component

Cast

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

No response

What command(s) is the bug in?

No response

Operating System

None

Describe the bug

When using cast with an RPC endpoint behind Cloudflare Proxy, responses are 403s.
When testing the same rpc call with curl, it works fine. It seems that using curl without a user agent also returns 403s, so it could be that cast doesn't set any user agent.

I found no option in cast to set request headers.

@sebastiendan sebastiendan added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Nov 27, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Nov 27, 2024
@zerosnacks zerosnacks added C-cast Command: cast T-feature Type: feature and removed T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Nov 28, 2024
@zerosnacks zerosnacks changed the title cast doesn't work with RPC endpoints behind Cloudflare Proxy feat(cast): add ability to specify request headers Nov 28, 2024
@zerosnacks
Copy link
Member

Generally supportive of this

We already support adding of custom headers in Alloy, should be relatively easy to add this to cast

https://github.com/alloy-rs/examples/blob/3b6d4a7cb465a0cb62a396735a8e26baa188ea55/examples/layers/examples/hyper_http_layer.rs#L92-L94

@zerosnacks zerosnacks added the first issue A good way to start contributing label Nov 28, 2024
@yash-atreya
Copy link
Member

yash-atreya commented Nov 28, 2024

Generally supportive of this

We already support adding of custom headers in Alloy, should be relatively easy to add this to cast

https://github.com/alloy-rs/examples/blob/3b6d4a7cb465a0cb62a396735a8e26baa188ea55/examples/layers/examples/hyper_http_layer.rs#L92-L94

I don't think we need a layer for this, the current foundy_common::provider implementation supports adding custom headers to the underlying reqwest::Client. See:

pub fn headers(mut self, headers: Vec<String>) -> Self {
.

We just need to expose a cli flag headers: Vec<String> in RpcOpts

pub struct RpcOpts {
, then instantiate a provider with headers set.

e.g usage:
cast call 0x.. "balanceOf(address)" 0x. --rpc-url --headers name:value

@sebastiendan
Copy link
Author

Would setting a default user-agent be a valid additional change? (might be tedious to keep specifying it)

@zerosnacks
Copy link
Member

Would setting a default user-agent be a valid additional change? (might be tedious to keep specifying it)

Given that cast is meant to be invoked standalone - independent of the context of a foundry project it cannot rely on the foundry.toml configuration. I would recommend assigning it to an environment variable and passing that in.

@yash-atreya
Copy link
Member

yash-atreya commented Nov 28, 2024

Would setting a default user-agent be a valid additional change? (might be tedious to keep specifying it)

Given that cast is meant to be invoked standalone - independent of the context of a foundry project it cannot rely on the foundry.toml configuration. I would recommend assigning it to an environment variable and passing that in.

We can use an env variable instead: ETH_RPC_HEADERS

PR is up

@yash-atreya yash-atreya self-assigned this Nov 28, 2024
@yash-atreya yash-atreya moved this from Todo to Ready For Review in Foundry Nov 28, 2024
@DaniPopes
Copy link
Member

I think a default user-agent still makes sense, curl does this too

@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Nov 29, 2024
@grandizzy grandizzy moved this from Done to Completed in Foundry Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast first issue A good way to start contributing T-feature Type: feature
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants