original http/agent code from node.js