refactor http encoder