HTTPRequest: code refactoring and optimization