Check conten-type and return 415 if not supported by route
Description
Noticed that Lighthouse does not check the content type of the request body and just tries to deserialize it, causing strange errors.
E.g. Error on Lodestar when trying to call getAttesterDuties with SSZ request body
May-28 11:04:57.066[] [31merror[39m: Failed to download attester duties epoch=0 - getAttesterDuties failed with status 400: BAD_REQUEST: body deserialize error: Error("expected value", line: 1, column: 1)
Error: getAttesterDuties failed with status 400: BAD_REQUEST: body deserialize error: Error("expected value", line: 1, column: 1)
As per spec, this route does not require to support SSZ request bodies and by default Lodestar will be using JSON but it would still be nice if Lighthouse could return a 415 error as this allows Lodestar to retry the request with JSON and cache for this route that SSZ is not supported, only sending JSON in subsequent requests.
Clients returning a proper status code would also allow to gradually support SSZ for more routes which based on data we gathered https://github.com/ChainSafe/lodestar/pull/6749#issuecomment-2128847283 would be quite benefitial.
Version
v5.1.3
Present Behaviour
Lighthouse tries to parse body without checking first if content type is supported
Expected Behaviour
Check Content-Type header and return 415 error if content type is not supported by route.
Steps to reproduce
I've been using Kurtosis to run the tests (with custom lodestar image)
participants:
- el_type: geth
el_image: ethereum/client-go:stable
cl_type: lodestar
cl_image: nflaig/lodestar:ssz-api
vc_type: lighthouse
vc_image: sigp/lighthouse:latest
count: 1
- el_type: geth
el_image: ethereum/client-go:stable
cl_type: lighthouse
cl_image: sigp/lighthouse:latest
vc_type: lodestar
vc_image: nflaig/lodestar:ssz-api
count: 1