Minor RPC cleanups

Some code movement and minor improvements, to prepare for HTTP REST support (#2844).

Even if HTTP REST is delayed or does not go in, these cleanups remain useful.

This belongs in rpcserver.h, as it is specific to the server side.