some docs

This commit is contained in:
renaynay 2020-03-30 09:37:11 +02:00
parent 2321f64d69
commit 142b5f7f33
No known key found for this signature in database
GPG key ID: 731E44FAAFCD0274
3 changed files with 5 additions and 1 deletions

View file

@ -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)

View file

@ -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"

View file

@ -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)
})