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 <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka 2021-07-23 18:48:22 +02:00 committed by GitHub
parent c0076cc7a2
commit be82c8714f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 11 deletions

View File

@ -1,8 +1,6 @@
package gateway package gateway
import ( import (
"net/http"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" gwruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1" ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@ -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{ v1Alpha1PbHandler := gateway.PbMux{
Registrations: v1Alpha1Registrations, Registrations: v1Alpha1Registrations,
Patterns: []string{"/eth/v1alpha1/"}, Patterns: []string{"/eth/v1alpha1/"},
@ -80,7 +75,6 @@ func DefaultConfig(enableDebugRPCEndpoints bool) MuxConfig {
} }
return MuxConfig{ return MuxConfig{
Handler: muxHandler,
V1PbMux: v1PbHandler, V1PbMux: v1PbHandler,
V1Alpha1PbMux: v1Alpha1PbHandler, V1Alpha1PbMux: v1Alpha1PbHandler,
} }

View File

@ -10,7 +10,6 @@ import (
func TestDefaultConfig(t *testing.T) { func TestDefaultConfig(t *testing.T) {
t.Run("Without debug endpoints", func(t *testing.T) { t.Run("Without debug endpoints", func(t *testing.T) {
cfg := DefaultConfig(false) cfg := DefaultConfig(false)
assert.NotNil(t, cfg.Handler)
assert.NotNil(t, cfg.V1PbMux.Mux) assert.NotNil(t, cfg.V1PbMux.Mux)
require.Equal(t, 1, len(cfg.V1PbMux.Patterns)) require.Equal(t, 1, len(cfg.V1PbMux.Patterns))
assert.Equal(t, "/eth/v1/", cfg.V1PbMux.Patterns[0]) 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) { t.Run("With debug endpoints", func(t *testing.T) {
cfg := DefaultConfig(true) cfg := DefaultConfig(true)
assert.NotNil(t, cfg.Handler)
assert.NotNil(t, cfg.V1PbMux.Mux) assert.NotNil(t, cfg.V1PbMux.Mux)
require.Equal(t, 1, len(cfg.V1PbMux.Patterns)) require.Equal(t, 1, len(cfg.V1PbMux.Patterns))
assert.Equal(t, "/eth/v1/", cfg.V1PbMux.Patterns[0]) assert.Equal(t, "/eth/v1/", cfg.V1PbMux.Patterns[0])

View File

@ -131,9 +131,12 @@ func (g *Gateway) Start() {
} }
corsMux := g.corsMiddleware(g.mux) 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{ g.server = &http.Server{
Addr: g.gatewayAddr, Addr: g.gatewayAddr,