{"_id":"@ru-hend/http-cookie-agent","name":"@ru-hend/http-cookie-agent","dist-tags":{"latest":"7.0.2"},"versions":{"7.0.2":{"name":"@ru-hend/http-cookie-agent","version":"7.0.2","description":"Allows cookies with every Node.js HTTP clients.","keywords":["agent","axios","cookies","fetch","got","http","https","needle","node-fetch","phin","request","superagent","tough-cookie","urllib","undici"],"homepage":"https://github.com/3846masa/http-cookie-agent#readme","bugs":{"url":"https://github.com/3846masa/http-cookie-agent/issues"},"repository":{"type":"git","url":"git+https://github.com/3846masa/http-cookie-agent.git"},"funding":"https://github.com/sponsors/3846masa","license":"MIT","author":{"name":"3846masa","email":"3846masahiro+git@gmail.com"},"exports":{"./http":"./http/index.js","./undici":"./undici/index.js","./undici/v6":"./undici/v6/index.js"},"dependencies":{"agent-base":"^7.1.4"},"devDependencies":{"@3846masa/configs":"github:3846masa/configs#6d886368a53bbe52a8dc599de1b24441691439ed","@babel/cli":"7.28.0","@babel/core":"7.28.0","@babel/plugin-proposal-explicit-resource-management":"7.27.4","@babel/preset-env":"7.28.0","@babel/preset-typescript":"7.27.1","@hapi/wreck":"18.1.0","@semantic-release/changelog":"6.0.3","@semantic-release/git":"10.0.1","@types/babel__core":"7.20.5","@types/needle":"3.3.0","@types/node":"20.19.7","@types/request":"2.48.12","@types/semver":"7.7.0","@types/superagent":"8.1.9","agentkeepalive":"4.6.0","axios":"1.10.0","disposablestack":"1.1.7","got":"14.4.7","http-proxy-agent":"7.0.2","needle":"3.3.1","node-fetch":"3.3.2","phin":"3.7.1","proxy":"2.2.0","request":"2.88.2","rimraf":"6.0.1","semantic-release":"24.2.6","semver":"7.7.2","superagent":"10.2.2","tough-cookie":"5.1.2","typescript":"5.8.3","undici":"7.10.0","undici__v6":"npm:undici@6.21.3","urllib":"4.7.1","vitest":"3.2.4"},"peerDependencies":{"tough-cookie":"^4.0.0 || ^5.0.0","undici":"npm:@ru-hend/undici"},"peerDependenciesMeta":{"undici":{"optional":true}},"packageManager":"pnpm@10.12.4","engines":{"node":">=10"},"pnpm":{"overrides":{"urllib>undici":"$undici"},"patchedDependencies":{"@semantic-release/git@10.0.1":"patches/@semantic-release__git@10.0.1.patch"}},"_id":"@ru-hend/http-cookie-agent@7.0.2","gitHead":"f89f6db2b695de30c9272cafe975645af5bf19e0","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-eElnDVfSX442h/Vn0DuJXOIubrnVTDBl/HrFkPoRR25WndADgu6nYuD74FcjMW4GcO5EANAgmyvW+aELSBkfjQ==","shasum":"f08aaf0c01b550c3cc2b75405128da2bce30d504","tarball":"https://registry.npmjs.org/@ru-hend/http-cookie-agent/-/http-cookie-agent-7.0.2.tgz","fileCount":30,"unpackedSize":32953,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCek/pJ4Bnsb1X8KtQhc0qe56B3dl3CctP7yeHF4vyHBQIhANxyJEYxGGLKMOJOImA1ARG1MjCAD8OqK1CP7h+OHAkx"}]},"_npmUser":{"name":"rulihenderson","email":"matsunagahisahde@gmail.com"},"directories":{},"maintainers":[{"name":"rulihenderson","email":"matsunagahisahde@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/http-cookie-agent_7.0.2_1754265366814_0.5569471705798632"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-03T23:56:06.681Z","7.0.2":"2025-08-03T23:56:06.984Z","modified":"2025-08-03T23:56:07.309Z"},"maintainers":[{"name":"rulihenderson","email":"matsunagahisahde@gmail.com"}],"description":"Allows cookies with every Node.js HTTP clients.","homepage":"https://github.com/3846masa/http-cookie-agent#readme","keywords":["agent","axios","cookies","fetch","got","http","https","needle","node-fetch","phin","request","superagent","tough-cookie","urllib","undici"],"repository":{"type":"git","url":"git+https://github.com/3846masa/http-cookie-agent.git"},"author":{"name":"3846masa","email":"3846masahiro+git@gmail.com"},"bugs":{"url":"https://github.com/3846masa/http-cookie-agent/issues"},"license":"MIT","readme":"# HTTP Cookie Agent\n\n![HTTP Cookie Agent](./docs/assets/ogp.jpg)\n\n[![github sponsors](https://flat.badgen.net/badge/GitHub%20Sponsors/Support%20me%20%E2%9D%A4/ff69b4?icon=github)](https://github.com/sponsors/3846masa)\n[![npm](https://flat.badgen.net/npm/v/http-cookie-agent)](https://www.npmjs.com/package/http-cookie-agent)\n[![license](https://flat.badgen.net/badge/license/MIT/blue)](LICENSE)\n[![standard-readme compliant](https://flat.badgen.net/badge/readme%20style/standard/green)](https://github.com/RichardLitt/standard-readme)\n\nAllows cookies with every Node.js HTTP clients (e.g. Node.js global fetch, undici, axios, node-fetch).\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Supported libraries](#supported-libraries)\n  - [Using with another Agent library](#using-with-another-agent-library)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\n```bash\nnpm install http-cookie-agent tough-cookie\n```\n\n## Usage\n\nSee also [examples](./examples) for more details.\n\n### Supported libraries\n\n| Library              | Supported?        |\n| -------------------- | ----------------- |\n| Node.js global fetch | ✅                |\n| `undici`             | ✅                |\n| `node:http`          | ✅                |\n| `node:https`         | ✅                |\n| `axios`              | ✅                |\n| `node-fetch`         | ✅                |\n| `got`                | ✅ <sup>\\*1</sup> |\n| `superagent`         | ✅ <sup>\\*1</sup> |\n| `request`            | ✅ <sup>\\*1</sup> |\n| `needle`             | ✅                |\n| `phin`               | ✅                |\n| `@hapi/wrech`        | ✅                |\n| `urllib`             | ✅                |\n| Bun global fetch     | ❌ <sup>\\*2</sup> |\n| Deno global fetch    | ❌ <sup>\\*2</sup> |\n\n\\*1: This library supports cookies by default. You may not need `http-cookie-agent`.\n\n\\*2: There have proprietary fetch implementation and is [not currently supported](https://github.com/3846masa/http-cookie-agent/issues/692).\n\n#### Node.js global fetch\n\nWhen you want to use Node.js global fetch, you should install `undici` additionally.\n\n| Node.js version | undici version         |\n| --------------- | ---------------------- |\n| v24             | `npm install undici@7` |\n| v23             | `npm install undici@6` |\n| v22             | `npm install undici@6` |\n| v20             | `npm install undici@6` |\n\n```js\nimport { CookieJar } from 'tough-cookie';\nimport { CookieAgent } from 'http-cookie-agent/undici/v6';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n#### `undici`\n\n```js\nimport { fetch } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { CookieAgent } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\nAlternatively, `http-cookie-agent` can be used as [interceptors](https://github.com/nodejs/undici/blob/v7.0.0/docs/docs/api/Dispatcher.md#dispatchercomposeinterceptors-interceptor).\nIn this case, the `cookie()` must be placed at the beginning of the interceptors.\n\n```js\nimport { fetch, interceptors } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { cookie } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new Agent()\n  .compose(cookie({ jar }))\n  .compose(interceptors.retry())\n  .compose(interceptors.redirect({ maxRedirections: 3 }));\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n#### `node:http` / `node:https`\n\n```js\nimport https from 'node:https';\n\nimport { CookieJar } from 'tough-cookie';\nimport { HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\nconst agent = new HttpsCookieAgent({ cookies: { jar } });\n\nhttps.get('https://example.com', { agent }, (res) => {\n  // ...\n});\n```\n\n#### `axios`\n\n```js\nimport axios from 'axios';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = axios.create({\n  httpAgent: new HttpCookieAgent({ cookies: { jar } }),\n  httpsAgent: new HttpsCookieAgent({ cookies: { jar } }),\n});\n\nawait client.get('https://example.com');\n```\n\n#### `node-fetch`\n\n```js\nimport fetch from 'node-fetch';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst httpAgent = new HttpCookieAgent({ cookies: { jar } });\nconst httpsAgent = new HttpsCookieAgent({ cookies: { jar } });\n\nawait fetch('https://example.com', {\n  agent: ({ protocol }) => {\n    return protocol === 'https:' ? httpsAgent : httpAgent;\n  },\n});\n```\n\n#### `got`\n\n:warning: `got` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/sindresorhus/got/tree/v11.8.2#cookies.\n\n```js\nimport got from 'got';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = got.extend({\n  agent: {\n    http: new HttpCookieAgent({ cookies: { jar } }),\n    https: new HttpsCookieAgent({ cookies: { jar } }),\n  },\n});\n\nawait client('https://example.com');\n```\n\n#### `superagent`\n\n:warning: `superagent` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/visionmedia/superagent/blob/v6.1.0/docs/index.md#saving-cookies.\n\n```js\nimport superagent from 'superagent';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\nconst mixedAgent = new MixedCookieAgent({ cookies: { jar } });\n\nconst client = superagent.agent().use((req) => req.agent(mixedAgent));\n\nawait client.get('https://example.com');\n```\n\n#### `request`\n\n:warning: `request` supports cookies by default. You may not need `http-cookie-agent`.\n\nSee https://github.com/request/request/tree/v2.88.1#examples.\n\n```js\nimport request from 'request';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = request.defaults({\n  agent: new MixedCookieAgent({ cookies: { jar } }),\n});\n\nclient.get('https://example.com', (_err, _res) => {\n  // ...\n});\n```\n\n#### `needle`\n\n```js\nimport needle from 'needle';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nawait needle('get', 'https://example.com', {\n  agent: new MixedCookieAgent({ cookies: { jar } }),\n});\n```\n\n#### `phin`\n\n```js\nimport phin from 'phin';\nimport { CookieJar } from 'tough-cookie';\nimport { MixedCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nawait phin({\n  url: 'https://example.com',\n  core: {\n    agent: new MixedCookieAgent({ cookies: { jar } }),\n  },\n});\n```\n\n#### `@hapi/wreck`\n\n```js\nimport Wreck from '@hapi/wreck';\nimport { CookieJar } from 'tough-cookie';\nimport { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/http';\n\nconst jar = new CookieJar();\n\nconst client = Wreck.defaults({\n  agents: {\n    http: new HttpCookieAgent({ cookies: { jar } }),\n    https: new HttpsCookieAgent({ cookies: { jar } }),\n    httpsAllowUnauthorized: new HttpsCookieAgent({ cookies: { jar } }),\n  },\n});\n\nawait client.get('https://example.com');\n```\n\n#### `urllib`\n\n```js\nimport { request, setGlobalDispatcher } from 'urllib';\nimport { CookieJar } from 'tough-cookie';\nimport { CookieAgent } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new CookieAgent({ cookies: { jar } });\nsetGlobalDispatcher(agent);\n\nawait request('https://example.com');\n```\n\n### Using with another Agent library\n\nIf you want to use another Agent library, wrap the agent in `createCookieAgent`.\n\n```js\nimport https from 'node:https';\n\nimport { HttpsAgent as KeepAliveAgent } from 'agentkeepalive';\nimport { CookieJar } from 'tough-cookie';\nimport { createCookieAgent } from 'http-cookie-agent/http';\n\nconst Agent = createCookieAgent(KeepAliveAgent);\n\nconst jar = new CookieJar();\nconst agent = new Agent({ cookies: { jar } });\n\nhttps.get('https://example.com', { agent }, (res) => {\n  // ...\n});\n```\n\n#### `undici`\n\nIf you want to use another undici Agent library, use `cookie` with the compose method.\n\n```js\nimport { fetch, ProxyAgent } from 'undici';\nimport { CookieJar } from 'tough-cookie';\nimport { cookie } from 'http-cookie-agent/undici';\n\nconst jar = new CookieJar();\nconst agent = new ProxyAgent({\n  /* ... */\n}).compose(cookie({ jar }));\n\nawait fetch('https://example.com', { dispatcher: agent });\n```\n\n## Contributing\n\nPRs accepted.\n\n## License\n\n[MIT (c) 3846masa](../LICENSE)\n","readmeFilename":"README.md","_rev":"1-ec0499cca5eae8ce01743c07a9219d7f"}