From 8bca66ac6408a03af52d65541f58384007ed50ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kapka?= Date: Fri, 23 Jul 2021 18:48:22 +0200 Subject: [PATCH] Do not require a handler function in the gateway (#9264) * Do not require a handler function in the gateway * test fix Co-authored-by: Raul Jordan Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> (cherry picked from commit be82c8714f50e605536888424df7e763b266ac11) --- beacon-chain/gateway/helpers.go | 6 ------ beacon-chain/gateway/helpers_test.go | 2 -- shared/gateway/gateway.go | 9 ++++++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/beacon-chain/gateway/helpers.go b/beacon-chain/gateway/helpers.go index 027b6c24f483..e0945d1faf00 100644 --- a/beacon-chain/gateway/helpers.go +++ b/beacon-chain/gateway/helpers.go @@ -1,8 +1,6 @@ package gateway import ( - "net/http" - gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" @@ -65,9 +63,6 @@ func DefaultConfig(enableDebugRPCEndpoints bool) MuxConfig { }, }), ) - muxHandler := func(h http.Handler, w http.ResponseWriter, req *http.Request) { - h.ServeHTTP(w, req) - } v1Alpha1PbHandler := gateway.PbMux{ Registrations: v1Alpha1Registrations, Patterns: []string{"/eth/v1alpha1/"}, @@ -80,7 +75,6 @@ func DefaultConfig(enableDebugRPCEndpoints bool) MuxConfig { } return MuxConfig{ - Handler: muxHandler, V1PbMux: v1PbHandler, V1Alpha1PbMux: v1Alpha1PbHandler, } diff --git a/beacon-chain/gateway/helpers_test.go b/beacon-chain/gateway/helpers_test.go index 02399f1f7123..280b4999fb20 100644 --- a/beacon-chain/gateway/helpers_test.go +++ b/beacon-chain/gateway/helpers_test.go @@ -10,7 +10,6 @@ import ( func TestDefaultConfig(t *testing.T) { t.Run("Without debug endpoints", func(t *testing.T) { cfg := DefaultConfig(false) - assert.NotNil(t, cfg.Handler) assert.NotNil(t, cfg.V1PbMux.Mux) require.Equal(t, 1, len(cfg.V1PbMux.Patterns)) assert.Equal(t, "/eth/v1/", cfg.V1PbMux.Patterns[0]) @@ -23,7 +22,6 @@ func TestDefaultConfig(t *testing.T) { t.Run("With debug endpoints", func(t *testing.T) { cfg := DefaultConfig(true) - assert.NotNil(t, cfg.Handler) assert.NotNil(t, cfg.V1PbMux.Mux) require.Equal(t, 1, len(cfg.V1PbMux.Patterns)) assert.Equal(t, "/eth/v1/", cfg.V1PbMux.Patterns[0]) diff --git a/shared/gateway/gateway.go b/shared/gateway/gateway.go index fdb52269c2fb..0cb639b3773b 100644 --- a/shared/gateway/gateway.go +++ b/shared/gateway/gateway.go @@ -131,9 +131,12 @@ func (g *Gateway) Start() { } corsMux := g.corsMiddleware(g.mux) - g.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - g.muxHandler(corsMux, w, r) - }) + + if g.muxHandler != nil { + g.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + g.muxHandler(corsMux, w, r) + }) + } g.server = &http.Server{ Addr: g.gatewayAddr,