How to use the set-cookie-parser.splitCookiesString function in set-cookie-parser

To help you get started, we’ve selected a few set-cookie-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github charleslo1 / weapp-cookie / src / CookieStore.js View on Github external
parse (setCookieStr = '', domain) {
    // parse
    var cookies = cookieParser.parse(cookieParser.splitCookiesString(setCookieStr))

    // 转换为 Cookie 对象
    return cookies.map((item) => {
      if (!item.domain) item.domain = domain
      return new Cookie(item)
    })
  }
github biblibre / urungi / test / server / api / login.spec.js View on Github external
it('should return a user object', async function () {
                let res = await request(app).get('/login');
                let setCookieHeader = res.headers['set-cookie'];
                if (setCookieHeader.length === 1) {
                    setCookieHeader = setCookieParser.splitCookiesString(setCookieHeader[0]);
                }
                const cookies = setCookieParser.parse(setCookieHeader, { map: true });
                const cookie = Object.values(cookies).map(c => c.name + '=' + c.value).join('; ');
                const xsrfToken = cookies['XSRF-TOKEN'].value;
                res = await request(app).post('/api/login')
                    .set('X-XSRF-TOKEN', xsrfToken)
                    .set('Cookie', cookie)
                    .send({ userName: 'administrator', password: 'urungi' })
                    .expect(200);

                expect(res.body).toHaveProperty('user');
                expect(res.body.user).toHaveProperty('roles');
                expect(res.body.user.roles).toContain('ADMIN');
            });
        });
github biblibre / urungi / test / server / helpers.js View on Github external
async function login (app, username = 'administrator', password = 'urungi') {
    const res = await request(app).get('/login');
    let setCookieHeader = res.headers['set-cookie'];
    if (setCookieHeader.length === 1) {
        setCookieHeader = setCookieParser.splitCookiesString(setCookieHeader[0]);
    }
    const cookies = setCookieParser.parse(setCookieHeader, { map: true });
    const cookie = Object.values(cookies).map(c => c.name + '=' + c.value).join('; ');
    const xsrfToken = cookies['XSRF-TOKEN'].value;
    const headers = {
        'X-XSRF-TOKEN': xsrfToken,
        Cookie: cookie,
    };

    await request(app).post('/api/login')
        .set(headers)
        .send({ userName: username, password: password });

    return headers;
}

set-cookie-parser

Parses set-cookie headers into objects

MIT
Latest version published 1 month ago

Package Health Score

79 / 100
Full package analysis