move some code from client-request to util