An asynchronous Cookie store (e.g. redis-cookie-store
) is no longer supported.
(If you create a CookieJar without options, this change has no effect.)
http-cookie-agent
allows to use an asynchronous Cookie store.
import axios from 'axios';
import { CookieJar } from 'tough-cookie';
import redis from 'redis';
import RedisCookieStore from 'redis-cookie-store';
import { HttpCookieAgent, HttpsCookieAgent } from 'http-cookie-agent/node:http';
const redisClient = redis.createClient();
const store = new RedisCookieStore(redisClient);
const jar = new CookieJar(store);
const client = axios.create({
httpAgent: new HttpCookieAgent({ cookies: { async_UNSTABLE: true, jar } }),
httpsAgent: new HttpsCookieAgent({ cookies: { async_UNSTABLE: true, jar } }),
});
await client.get('https://example.com');
- Node.js v14.18.0 / v16.0.0 or above
- Update requirements.
- The wrapper function are exported as "named exports".
- No longer refers to
config.withCredentials
. config.httpAgent
/config.httpsAgent
cannot use withaxios-cookiejar-support
.config.jar
no longer accepts boolean.- Invalid cookies will always be ignored.
- Node.js v12.19.0 / v14.5.0 or above
[email protected]
or above[email protected]
or above
// CommonJS
- const axiosCookieJarSupport = require('axios-cookiejar-support');
+ const { wrapper: axiosCookieJarSupport } = require('axios-cookiejar-support');
// ES Module
- import axiosCookieJarSupport from 'axios-cookiejar-support';
+ import { wrapper as axiosCookieJarSupport } from 'axios-cookiejar-support';
// Remove config.withCredentials
axios.get('https://example.com', {
jar: new CookieJar(),
- withCredentials: true,
});
If you want to prevent sending cookies, unset config.jar
directly.
// Remove config.jar for preventing to send cookie
axios.get('https://example.com', {
- jar: new CookieJar(),
- withCredentials: false,
});
http-cookie-agent
allows to use another Agent with CookieJar.
import axios from 'axios';
import { CookieJar } from 'tough-cookie';
import { createCookieAgent } from 'http-cookie-agent';
import httpProxyAgent from 'http-proxy-agent';
import httpsProxyAgent from 'https-proxy-agent';
const HttpProxyCookieAgent = createCookieAgent(httpProxyAgent.HttpProxyAgent);
const HttpsProxyCookieAgent = createCookieAgent(httpsProxyAgent.HttpsProxyAgent);
const jar = new CookieJar();
const client = axios.create({
httpAgent: new HttpProxyCookieAgent({ jar, hostname: '127.0.0.1', port: 8080 }),
httpsAgent: new HttpsProxyCookieAgent({ jar, hostname: '127.0.0.1', port: 8080 }),
});
await client.get('https://example.com');
// Cannot use boolean as config.jar since v2.x
+ const cookieJar = new CookieJar();
axios.get('https://example.com', {
- jar: true,
+ jar: cookieJar,
});
Up to v1.x, axios-cookie-jar
throws an error by default when a client receives invalid cookies.
However, since v2.0, axios-cookie-jar
will always ignore invalid cookies.
const cookieJar = new CookieJar();
axios.get('https://example.com', {
jar: cookieJar,
- ignoreCookieErrors: true,
});