{"id":16370256,"url":"https://github.com/delvedor/hpagent","last_synced_at":"2025-04-08T09:06:54.877Z","repository":{"id":37936153,"uuid":"280144093","full_name":"delvedor/hpagent","owner":"delvedor","description":"A ready to use http and https agent for working with proxies that keeps connections alive!","archived":false,"fork":false,"pushed_at":"2023-06-13T09:53:09.000Z","size":46,"stargazers_count":178,"open_issues_count":18,"forks_count":37,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-05-22T00:04:07.847Z","etag":null,"topics":["agent","http","https","keep-alive","proxy"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delvedor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-16T12:08:32.000Z","updated_at":"2024-06-18T12:28:39.533Z","dependencies_parsed_at":"2024-06-18T12:28:38.015Z","dependency_job_id":"993378cc-9613-4208-bd6b-8bd19085e53f","html_url":"https://github.com/delvedor/hpagent","commit_stats":{"total_commits":33,"total_committers":10,"mean_commits":3.3,"dds":0.5454545454545454,"last_synced_commit":"96f45f1d40bfbdfd0fcc84cdba056be6e0fb8f4c"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delvedor%2Fhpagent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delvedor%2Fhpagent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delvedor%2Fhpagent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delvedor%2Fhpagent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delvedor","download_url":"https://codeload.github.com/delvedor/hpagent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","http","https","keep-alive","proxy"],"created_at":"2024-10-11T03:04:30.088Z","updated_at":"2025-04-08T09:06:54.857Z","avatar_url":"https://github.com/delvedor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hpagent\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)  ![build](https://github.com/delvedor/hpagent/workflows/build/badge.svg). ![npm](https://img.shields.io/npm/dm/hpagent)\n\nA ready to use http and https agent for working with proxies that keeps connections alive!\n\n## Install\n\n```\nnpm install hpagent\n```\n\n## Usage\n\nBased on your infrastructure, you should use the http agent or the https agent.\nThe following table will help you picking the right one.\n\n| Type              | Proxy  | Server |\n|-------------------|--------|--------|\n| `HttpProxyAgent`  | HTTP   | HTTP   |\n| `HttpProxyAgent`  | HTTPS  | HTTP   |\n| `HttpsProxyAgent` | HTTP   | HTTPS  |\n| `HttpsProxyAgent` | HTTPS  | HTTPS  |\n\n```js\nconst { HttpProxyAgent, HttpsProxyAgent } = require('hpagent')\n```\n\nOnce you have understood the right agent for your use case, you can instance it. It takes the same parameter of the Node.js core's http(s) agent and an additional `proxy` option, which is the url of your proxy.\n\n```js\nconst http = require('http')\nconst { HttpProxyAgent } = require('hpagent')\n\nconst agent = new HttpProxyAgent({\n  keepAlive: true,\n  keepAliveMsecs: 1000,\n  maxSockets: 256,\n  maxFreeSockets: 256,\n  proxy: 'http://localhost:8080'\n})\n\nhttp.get('http://localhost:9200', { agent })\n    .on('response', console.log)\n    .end()\n```\n\nIf your proxy requires basic authentication, you can configure it in the proxy url:\n\n```js\nconst http = require('http')\nconst { HttpProxyAgent } = require('hpagent')\n\nconst agent = new HttpProxyAgent({\n  keepAlive: true,\n  keepAliveMsecs: 1000,\n  maxSockets: 256,\n  maxFreeSockets: 256,\n  proxy: 'http://user:pwd@localhost:8080'\n})\n\nhttp.get('http://localhost:9200', { agent })\n    .on('response', console.log)\n    .end()\n```\n\nYou can also pass custom options intended only for the proxy CONNECT request with the `proxyConnectOptions` option,\nsuch as headers or `tls.connect()` options:\n\n```js\nconst fs = require('fs')\nconst http = require('http')\nconst { HttpProxyAgent } = require('hpagent')\n\nconst agent = new HttpProxyAgent({\n  keepAlive: true,\n  keepAliveMsecs: 1000,\n  maxSockets: 256,\n  maxFreeSockets: 256,\n  proxy: 'https://localhost:8080',\n  proxyConnectOptions: {\n    headers: {\n      'Proxy-Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l',\n    },\n    ca: [ fs.readFileSync('custom-proxy-cert.pem') ]\n  }\n})\n\nhttp.get('http://localhost:9200', { agent })\n    .on('response', console.log)\n    .end()\n```\n\n## Integrations\n\nFollowing you can find the list of userland http libraries that are tested with this agent.\n\n### [got](https://github.com/sindresorhus/got)\n\n```js\ngot('http://localhost:9200', {\n  agent: {\n    http: new HttpProxyAgent({\n      keepAlive: true,\n      keepAliveMsecs: 1000,\n      maxSockets: 256,\n      maxFreeSockets: 256,\n      scheduling: 'lifo',\n      proxy: 'http://localhost:8080'\n    })\n  }\n})\n```\n\n### [needle](https://github.com/tomas/needle)\n\n```js\nneedle('get', 'http://localhost:9200', {\n  agent: new HttpProxyAgent({\n    keepAlive: true,\n    keepAliveMsecs: 1000,\n    maxSockets: 256,\n    maxFreeSockets: 256,\n    scheduling: 'lifo',\n    proxy: 'http://localhost:8080'\n  })\n})\n```\n\n### [node-fetch](https://github.com/node-fetch/node-fetch)\n\n```js\nfetch('http://localhost:9200', {\n  agent: new HttpProxyAgent({\n    keepAlive: true,\n    keepAliveMsecs: 1000,\n    maxSockets: 256,\n    maxFreeSockets: 256,\n    scheduling: 'lifo',\n    proxy: 'http://localhost:8080'\n  })\n})\n```\n\n### [simple-get](https://github.com/feross/simple-get)\n\n```js\nsget.concat({\n  url: `http://${server.address().address}:${server.address().port}`,\n  agent: new HttpProxyAgent({\n    keepAlive: true,\n    keepAliveMsecs: 1000,\n    maxSockets: 256,\n    maxFreeSockets: 256,\n    scheduling: 'lifo',\n    proxy: `https://${proxy.address().address}:${proxy.address().port}`\n  })\n}, function (err, response, data) {\n  // handle the response\n})\n```\n\n## License\n\nThis software is licensed under the [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelvedor%2Fhpagent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelvedor%2Fhpagent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelvedor%2Fhpagent/lists"}