refactor doHttpRequest function