How to use the set-cookie-parser.parse 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 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 / 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 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 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;
github rancher / ember-api-store / addon / services / store.js View on Github external
function copyCookies(obj) {
      if ( !obj || !obj.headers ) {
        return;
      }

      const headers = obj.headers.get('set-cookie');

      if ( headers ) {
        setCookieParser(headers).forEach((opts) => {
          const name = opts.name;
          const value = opts.value;

          delete opts.name;
          delete opts.value
          opts.raw = true;

          cookieSvc.write(name, value, opts);
        });
      }
    }
  },
github rancher / ember-api-store / addon / services / store.js View on Github external
function copyCookies(obj) {
      if ( !obj || !obj.headers ) {
        return;
      }

      const headers = obj.headers.get('set-cookie');

      if ( headers ) {
        setCookieParser(headers).forEach((opts) => {
          const name = opts.name;
          const value = opts.value;

          delete opts.name;
          delete opts.value
          opts.raw = true;

          cookieSvc.write(name, value, opts);
        });
      }
    }
  },

set-cookie-parser

Parses set-cookie headers into objects

MIT
Latest version published 18 days ago

Package Health Score

85 / 100
Full package analysis