refactor http protocol functions