Skip to content

Commit

Permalink
Do not require a handler function in the gateway (#9264)
Browse files Browse the repository at this point in the history
* 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>
(cherry picked from commit be82c87)
  • Loading branch information
rkapka authored and prestonvanloon committed Jul 30, 2021
1 parent b365090 commit 8bca66a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
6 changes: 0 additions & 6 deletions beacon-chain/gateway/helpers.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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/"},
Expand All @@ -80,7 +75,6 @@ func DefaultConfig(enableDebugRPCEndpoints bool) MuxConfig {
}

return MuxConfig{
Handler: muxHandler,
V1PbMux: v1PbHandler,
V1Alpha1PbMux: v1Alpha1PbHandler,
}
Expand Down
2 changes: 0 additions & 2 deletions beacon-chain/gateway/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand Down
9 changes: 6 additions & 3 deletions shared/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bca66a

Please sign in to comment.