How to use set-cookie-parser - 10 common examples

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 mvdicarlo / postybirb / src / electron-src / src / got-request.js View on Github external
.then((res) => {
        if (res.headers['set-cookie'] && profileId) { // TODO: I think I only implemented this because of SoFurry. Might be worth removing this logic.
          const _cookies = setCookie.parse(res, {
            decodeValues: false
          });
          const cookieSession = session.fromPartition(`persist:${profileId}`).cookies;
          _cookies.forEach((c) => {
            c.domain = c.domain || res.request.gotOptions.host;
            const converted = _convertCookie(c);
            const now = new Date();
            converted.expirationDate = now.setMonth(now.getMonth() + 4); // add 4 months
            cookieSession.set(converted, function(err) {
              if (err) {
                console.warn(err, this);
              }
            }.bind(converted));
          });
        }
        resolve(res);
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 charleslo1 / weapp-cookie / src / Cookie.js View on Github external
set (setCookieStr = '') {
    var cookie = cookieParser.parse(setCookieStr)[0]
    if (cookie) {
      Object.assign(this, cookie)
      // 更新设置时间
      this.dateTime = new Date()
    }

    return this
  }
github jo0ger / node-server / app / lib / plugin / egg-codoon / lib / codoon.js View on Github external
let success = true
        try {
            await this.http.post('http://sso.codoon.com/login', Object.assign({
                forever: 'on',
                app_id: 'www',
                next: '/'
            }, this.config), {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                // 禁止 302,不然拿不到 cookie
                maxRedirects: 0
            })
            this.log('咕咚登录成功')
        } catch (err) {
            const cookies = setCookie.parse(err.response) || []
            const sessionIdCookie = cookies.find(c => c.name === 'sessionid')
            if (sessionIdCookie) {
                const sessionId = sessionIdCookie.value
                this.log('咕咚登录成功,sessionid=' + sessionId)
                await this.cache({ sessionId })
            } else {
                success = false
                this.log('咕咚登录失败')
            }
        }
        return success
    }
github biblibre / urungi / test / server / api / login.spec.js View on Github external
it('should return status 401', async function () {
                const res = await agent.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;
                return request(app).post('/api/login')
                    .set('X-XSRF-TOKEN', xsrfToken)
                    .set('Cookie', cookie)
                    .send({ userName: 'administrator', password: 'invalidpassword' })
                    .expect(401);
            });
        });
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 mcibique / express-security / tests / e2e / session.spec.js View on Github external
.expect(function (response) {
          let cookies = cookieParser.parse(response);
          anotherSessionCookie = cookies.find(cookie => cookie.name === 'session');
        });
    });
github biblibre / urungi / test / server / common.js View on Github external
async function login (agent, username = 'administrator', password = 'urungi') {
    const res = await agent.get('/login');
    const cookies = setCookieParser.parse(res, { map: true });
    const xsrfToken = cookies['XSRF-TOKEN'].value;
    await agent.post('/api/login')
        .set('X-XSRF-TOKEN', xsrfToken)
        .send({ userName: username, password: password });

    return xsrfToken;
}
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;
}
github exogen / node-fetch-har / index.js View on Github external
setCookies.forEach(headerValue => {
      let parsed;
      try {
        parsed = setCookie.parse(headerValue);
      } catch (err) {
        return;
      }
      parsed.forEach(cookie => {
        const { name, value, path, domain, expires, httpOnly, secure } = cookie;
        const harCookie = {
          name,
          value,
          httpOnly: httpOnly || false,
          secure: secure || false
        };
        if (path) {
          harCookie.path = path;
        }
        if (domain) {
          harCookie.domain = domain;

set-cookie-parser

Parses set-cookie headers into objects

MIT
Latest version published 1 month ago

Package Health Score

79 / 100
Full package analysis