restapi: add event handler wrapper

This commit is contained in:
zsfelfoldi 2025-10-23 09:28:19 +02:00
parent 17173d0014
commit 7eac50fe88
2 changed files with 16 additions and 1 deletions

View file

@ -109,7 +109,7 @@ func (s *BeaconApiServer) RestAPI(server *restapi.Server) restapi.API {
router.HandleFunc("/eth/v1/beacon/headers/head", server.WrapHandler(s.handleHeadHeader, false, false, false)).Methods("GET")
router.HandleFunc("/eth/v1/beacon/light_client/bootstrap/{checkpointhash}", server.WrapHandler(s.handleBootstrap, false, false, false)).Methods("GET")
router.HandleFunc("/eth/v2/beacon/blocks/{blockhash}", server.WrapHandler(s.handleBlocks, false, false, false)).Methods("GET")
router.HandleFunc("/eth/v1/events", s.eventServer.Handler("headEvent"))
router.HandleFunc("/eth/v1/events", server.WrapEventHandler(s.eventServer.Handler("headEvent")))
}
}

View file

@ -22,10 +22,12 @@ import (
"io/ioutil"
"net/http"
"net/url"
"time"
"github.com/elnormous/contenttype"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
@ -149,3 +151,16 @@ func (s *Server) WrapHandler(handler WrappedHandler, expectBody, allowRlpBody, a
}
}
}
func (s *Server) WrapEventHandler(handler func(resp http.ResponseWriter, req *http.Request)) func(resp http.ResponseWriter, req *http.Request) {
return func(resp http.ResponseWriter, req *http.Request) {
rc := http.NewResponseController(resp)
if err := rc.SetReadDeadline(time.Time{}); err != nil {
log.Error("Could not set read deadline for events request", "error", err)
}
if err := rc.SetWriteDeadline(time.Time{}); err != nil {
log.Error("Could not set read deadline for events request", "error", err)
}
handler(resp, req)
}
}