foundry
foundry copied to clipboard
Assume json content type
Component
Anvil
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
What version of Foundry are you on?
latest
What command(s) is the bug in?
No response
Operating System
macOS (Apple Silicon)
Describe the bug
Many nodes (hardhat, ganache) will work with ill-formatted RPC requests and will assume that they are dealing with JSON data. For example:
curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://127.0.0.1:8545
Works with hardhat node, but anvil will throw:
{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid request"}}
My suggestion would be to either:
- Improve error message (wrong content-type?)
- Assume it's JSON and make it work anyway.
I can work on a fix if you all agree this is a good idea.
I have observed hardhat not requiring the content type header, are you sure that geth works without it? I've observed geth not working without Content-Type: application/json. It seems like bad practice to follow lead in introducing bugs, altho it would be nice to have compatibility. cast rpc fixes this
Hmmm I am sure that services like alchemy support it.
Alchemy most likely uses a proxy in front of Geth, so figuring out Geth's behavior from what Alchemy does is not really possible
Yeah, yeah. What I meant is that it's a wildly spread incorrect behavior.
I just checked that geth/erigon doesn't support it. I'll update the issue description.
Note that Infura ignores the client's content-type header entirely. I see how that makes things convenient but I think this is too lax.
usr:~ $ echo -n '[]' | http post http://127.0.0.1:8545
HTTP/1.1 200 OK
access-control-allow-origin: *
content-length: 79
content-type: application/json
date: Fri, 29 Jul 2022 11:30:58 GMT
vary: origin
vary: access-control-request-method
vary: access-control-request-headers
{
"error": {
"code": -32600,
"message": "Invalid request"
},
"id": null,
"jsonrpc": "2.0"
}
maybe a message like
"message": "The JSON sent is not a valid request object."
Confirmed that geth does not do this: https://github.com/ethereum/go-ethereum/blob/0be9d76e3702cfae92f042cf6a113e22479de3f5/rpc/http.go#L33-L39
Alchemy and Infura likely just sets it for you
Closing—already done