pi_http: remove duplicated code