Skip to content

Commit 0f86a16

Browse files
authored
builder: api calls should have appropriate headers (#14961)
* adding correct headers when posting for validator registration on builder api * changelog
1 parent 972c22b commit 0f86a16

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

api/client/builder/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ go_test(
4646
data = glob(["testdata/**"]),
4747
embed = [":go_default_library"],
4848
deps = [
49+
"//api:go_default_library",
4950
"//api/server/structs:go_default_library",
5051
"//config/fieldparams:go_default_library",
5152
"//config/params:go_default_library",

api/client/builder/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ func (c *Client) do(ctx context.Context, method string, path string, body io.Rea
154154
if err != nil {
155155
return
156156
}
157+
if method == http.MethodPost {
158+
req.Header.Set("Content-Type", api.JsonMediaType)
159+
}
160+
req.Header.Set("Accept", api.JsonMediaType)
157161
req.Header.Add("User-Agent", version.BuildData())
158162
for _, o := range opts {
159163
o(req)

api/client/builder/client_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/prysmaticlabs/go-bitfield"
15+
"github.com/prysmaticlabs/prysm/v5/api"
1516
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
1617
"github.com/prysmaticlabs/prysm/v5/config/params"
1718
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
@@ -89,6 +90,8 @@ func TestClient_RegisterValidator(t *testing.T) {
8990
expectedPath := "/eth/v1/builder/validators"
9091
hc := &http.Client{
9192
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
93+
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
94+
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
9295
body, err := io.ReadAll(r.Body)
9396
defer func() {
9497
require.NoError(t, r.Body.Close())
@@ -364,8 +367,8 @@ func TestSubmitBlindedBlock(t *testing.T) {
364367
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
365368
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
366369
require.Equal(t, "bellatrix", r.Header.Get("Eth-Consensus-Version"))
367-
require.Equal(t, "application/json", r.Header.Get("Content-Type"))
368-
require.Equal(t, "application/json", r.Header.Get("Accept"))
370+
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
371+
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
369372
return &http.Response{
370373
StatusCode: http.StatusOK,
371374
Body: io.NopCloser(bytes.NewBufferString(testExampleExecutionPayload)),
@@ -392,8 +395,8 @@ func TestSubmitBlindedBlock(t *testing.T) {
392395
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
393396
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
394397
require.Equal(t, "capella", r.Header.Get("Eth-Consensus-Version"))
395-
require.Equal(t, "application/json", r.Header.Get("Content-Type"))
396-
require.Equal(t, "application/json", r.Header.Get("Accept"))
398+
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
399+
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
397400
return &http.Response{
398401
StatusCode: http.StatusOK,
399402
Body: io.NopCloser(bytes.NewBufferString(testExampleExecutionPayloadCapella)),
@@ -423,8 +426,8 @@ func TestSubmitBlindedBlock(t *testing.T) {
423426
Transport: roundtrip(func(r *http.Request) (*http.Response, error) {
424427
require.Equal(t, postBlindedBeaconBlockPath, r.URL.Path)
425428
require.Equal(t, "deneb", r.Header.Get("Eth-Consensus-Version"))
426-
require.Equal(t, "application/json", r.Header.Get("Content-Type"))
427-
require.Equal(t, "application/json", r.Header.Get("Accept"))
429+
require.Equal(t, api.JsonMediaType, r.Header.Get("Content-Type"))
430+
require.Equal(t, api.JsonMediaType, r.Header.Get("Accept"))
428431
var req structs.SignedBlindedBeaconBlockDeneb
429432
err := json.NewDecoder(r.Body).Decode(&req)
430433
require.NoError(t, err)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- adding in content type and accept headers for builder API call on registration

0 commit comments

Comments
 (0)