diff --git a/node/node.go b/node/node.go index b0169b99b3..5f5ec33eae 100644 --- a/node/node.go +++ b/node/node.go @@ -686,6 +686,8 @@ func (n *Node) apis() []rpc.API { } } +// RegisterApisFromWhitelist checks the given modules' availability, generates a whitelist based on the allowed modules, +// and then registers all of the APIs exposed by the services. func RegisterApisFromWhitelist(apis []rpc.API, modules []string, srv *rpc.Server) error { if bad, available := rpc.CheckModuleAvailability(modules, apis); len(bad) > 0 { log.Error("Unavailable modules in HTTP API list", "unavailable", bad, "available", available) diff --git a/node/rpcstack.go b/node/rpcstack.go index 3c40031537..96407625b8 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -139,6 +139,8 @@ func newGzipHandler(next http.Handler) http.Handler { }) } +// NewWebsocketUpgradeHandler returns a websocket handler that serves an incoming request only if it contains an upgrade +// request to the websocket protocol. If not, serves the the request with the http handler. func NewWebsocketUpgradeHandler(h http.Handler, ws http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if isWebsocket(r) { @@ -151,6 +153,7 @@ func NewWebsocketUpgradeHandler(h http.Handler, ws http.Handler) http.Handler { }) } +// isWebsocket checks the header of an http request for a websocket upgrade request. func isWebsocket(r *http.Request) bool { return strings.ToLower(r.Header.Get("Upgrade")) == "websocket" && strings.ToLower(r.Header.Get("Connection")) == "upgrade" diff --git a/rpc/websocket.go b/rpc/websocket.go index b49553c160..b7ec56c6a6 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -62,7 +62,6 @@ func (s *Server) WebsocketHandler(allowedOrigins []string) http.Handler { log.Debug("WebSocket upgrade failed", "err", err) return } - codec := newWebsocketCodec(conn) s.ServeCodec(codec, 0) })