axios-cookiejar-support didn't save all cookies

99 views Asked by At

It's a demo of axios-cookiejar-support.

'use strict';

const { default: axios } = require('axios');
const { CookieJar } = require('tough-cookie');
const { wrapper } = require('axios-cookiejar-support');

const jar = new CookieJar();
const client = wrapper(axios.create({ 
        jar
}));

client.get('https://www.baidu.com').then((res) => {
  console.log(res.headers,jar);
});

I got these output:

Object [AxiosHeaders] {
  connection: 'close',
  ...
  server: 'BWS/1.1',
  'set-cookie': [
    'BD_NOT_HTTPS=1; path=/; Max-Age=300',
    'BIDUPSID=54A36DE3537EF8B3FE172A6DFEE598C2; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com',
    'PSTM=1698380238; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com',
    'BAIDUID=54A36DE3537EF8B34B0104D701907056:FG=1; max-age=31536000; expires=Sat, 26-Oct-24 04:17:18 GMT; domain=.baidu.com; path=/; version=1; comment=bd'
  ],
  traceid: '1698380238264810573817821645337925175101',
  'x-ua-compatible': 'IE=Edge,chrome=1'
} CookieJar {
  rejectPublicSuffixes: true,
  enableLooseMode: false,
  allowSpecialUseDomain: true,
  store: { idx: [Object: null prototype] {
    localhost: [Object: null prototype] {
      '/': [Object: null prototype] {
        BD_NOT_HTTPS: Cookie="BD_NOT_HTTPS=1; Max-Age=300; Path=/; hostOnly=true; aAge=35ms; cAge=35ms"
      }
    }
  } },
  prefixSecurity: 'silent',
  ...
}

I saw there's 4 cookies in the response, but the cookiejar only saved 1 cookie.

Why's that? How can I save all of cookies?

Here are the dependencies:

{
  "dependencies": {
    "axios": "^1.5.1",
    "axios-cookiejar-support": "^4.0.7",
    "tough-cookie": "^4.1.3"
  }
}
0

There are 0 answers