cli: reduce DefaultRequestHandler memory allocations
Summary:
Simpler code, fewer allocations. No change of behavior. The code has good test coverage in interface_bitcoin_cli.py.
This is a backport of core#19453
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D9988