Browse Source

return method not found error

if somebody tries to access WS method in non-ws context
pull/521/head
Anton Kaliaev 7 years ago
committed by Ethan Buchman
parent
commit
f8b152972f
1 changed files with 2 additions and 6 deletions
  1. +2
    -6
      rpc/lib/server/handlers.go

+ 2
- 6
rpc/lib/server/handlers.go View File

@ -123,14 +123,10 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han
return
}
rpcFunc := funcMap[request.Method]
if rpcFunc == nil {
if rpcFunc == nil || rpcFunc.ws {
WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(request.ID))
return
}
if rpcFunc.ws {
WriteRPCResponseHTTP(w, types.RPCInternalError(request.ID, errors.New("Trying to use Websocket method in non-ws context")))
return
}
args, err := jsonParamsToArgsRPC(rpcFunc, request.Params)
if err != nil {
WriteRPCResponseHTTP(w, types.RPCInvalidParamsError(request.ID, errors.Wrap(err, "Error converting json params to arguments")))
@ -234,7 +230,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc, logger log.Logger) func(http.ResponseWrit
// Exception for websocket endpoints
if rpcFunc.ws {
return func(w http.ResponseWriter, r *http.Request) {
WriteRPCResponseHTTP(w, types.RPCInternalError("", errors.New("Trying to use Websocket method in non-ws context")))
WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(""))
}
}
// All other endpoints


Loading…
Cancel
Save