How to use the request.cookie function in request

To help you get started, we’ve selected a few request 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 pikax / swgoh / dist / index.cjs.js View on Github external
form = {
                            username: username,
                            password: password,
                            csrfmiddlewaretoken: csrfmiddlewaretoken,
                        };
                        r = {
                            uri: uri,
                            form: form,
                            method: "POST",
                            jar: jar,
                            followAllRedirects: true,
                            headers: {
                                referer: host
                            }
                        };
                        jar.setCookie(request.cookie('csrftoken=' + csrf), uri);
                        return [4 /*yield*/, this._queue.queue(r).then(function (x) { return x.body; })];
                    case 2:
                        html = _a.sent();
                        // console.log('html:' + html)
                        //todo change to regex expression with word probably
                        return [2 /*return*/, html.indexOf(username) >= 0];
                }
            });
        });
github sokcuri / TweetDeckPlayer / src / index.js View on Github external
cookies.forEach(cookie => {
        const cookieString = `${cookie.name}=${cookie.value};`;
        jar.setCookie(request.cookie(cookieString), 'https://ton.twitter.com');
      });
      // http 요청을 보내고 저장
github Kong / httpsnippet / test / fixtures / output / node / request / cookies.js View on Github external
var request = require("request");

var jar = request.jar();
jar.setCookie(request.cookie("foo=bar"), "http://mockbin.com/har");
jar.setCookie(request.cookie("bar=baz"), "http://mockbin.com/har");

var options = {method: 'POST', url: 'http://mockbin.com/har', jar: 'JAR'};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
github goFrendiAsgard / chimera-framework / test / test-web.js View on Github external
it('plus-one-session should plus session.data by one', function (done) {
    let cookieJar = request.jar()
    let cookie = request.cookie('connect.sid=' + sessionId)
    let url = 'http://localhost:3010/plus-one-session'
    cookieJar.setCookie(cookie, url)
    request({url: url, jar: cookieJar}, function (error, response, body) {
      if (error) {
        return done(error)
      }
      assert.equal(body, '2')
      return done()
    })
  })
github typestack / routing-controllers / test / functional / action-params.spec.ts View on Github external
describe("@CookieParam should give a proper values from request headers", () => {
        const request = require("request");
        const jar = request.jar();
        const url2 = "http://127.0.0.1:3002/questions";
        jar.setCookie(request.cookie("token=31ds31das231sad12"), url2);
        jar.setCookie(request.cookie("count=20"), url2);
        jar.setCookie(request.cookie("showAll=false"), url2);

        const requestOptions = {
            jar: jar
        };
        assertRequest([3001, 3002], "get", "questions", requestOptions, response => {
            expect(cookieParamToken).to.be.equal("31ds31das231sad12");
            expect(cookieParamCount).to.be.equal(20);
            expect(cookieParamShowAll).to.be.equal(false);
            expect(response).to.be.status(200);
            expect(response).to.have.header("content-type", "text/html; charset=utf-8");
        });
    });
github typestack / routing-controllers / test / functional / action-params.spec.ts View on Github external
describe("@CookieParam should give a proper values from request headers", () => {
        const request = require("request");
        const jar = request.jar();
        const url2 = "http://127.0.0.1:3002/questions";
        jar.setCookie(request.cookie("token=31ds31das231sad12"), url2);
        jar.setCookie(request.cookie("count=20"), url2);
        jar.setCookie(request.cookie("showAll=false"), url2);

        const requestOptions = {
            jar: jar
        };
        assertRequest([3001, 3002], "get", "questions", requestOptions, response => {
            expect(cookieParamToken).to.be.equal("31ds31das231sad12");
            expect(cookieParamCount).to.be.equal(20);
            expect(cookieParamShowAll).to.be.equal(false);
            expect(response).to.be.status(200);
            expect(response).to.have.header("content-type", "text/html; charset=utf-8");
        });
    });
github dshved / fridaybot / server / bot / commands / devlife.js View on Github external
const cheerio = require('cheerio');
const request = require('request');
const iconv = require('iconv-lite');

const j = request.jar();
const cookie = request.cookie('entriesOnPage=20;types=gif');
const url = 'https://developerslife.ru/';
j.setCookie(cookie, url);

function getEntries(param, cb) {
  request(
    {
      url: `https://developerslife.ru/${param}`,
      encoding: null,
      jar: j,
    },
    (err, res, body) => {
      const $ = cheerio.load(iconv.decode(body, 'utf-8'), {
        decodeEntities: false,
      });
      const entryes = $('.entry');
      const array = [];
github IBM / openapi-to-graphql / packages / openapi-to-graphql / src / resolver_builder.ts View on Github external
}

  if (typeof securityRequirement === 'string') {
    const security = data.security[securityRequirement]
    switch (security.def.type) {
      case 'apiKey':
        const apiKey =
          _openAPIToGraphQL.security[sanitizedSecurityRequirement].apiKey
        if ('in' in security.def) {
          if (typeof security.def.name === 'string') {
            if (security.def.in === 'header') {
              authHeaders[security.def.name] = apiKey
            } else if (security.def.in === 'query') {
              authQs[security.def.name] = apiKey
            } else if (security.def.in === 'cookie') {
              authCookie = NodeRequest.cookie(`${security.def.name}=${apiKey}`)
            }
          } else {
            throw new Error(
              `Cannot send API key in '${JSON.stringify(security.def.in)}'`
            )
          }
        }
        break

      case 'http':
        switch (security.def.scheme) {
          case 'basic':
            const username =
              _openAPIToGraphQL.security[sanitizedSecurityRequirement].username
            const password =
              _openAPIToGraphQL.security[sanitizedSecurityRequirement].password
github Kong / unirest-nodejs / lib / request.js View on Github external
Request.prototype.cookie = function cookie (name, value, url) {
  if (!this.options.jar) {
    this.options.jar = Unirest.request.jar()
  }

  try {
    this.options.jar.setCookie(
      request.cookie(name + '=' + value),
      url
    )
  } catch (error) {
    throw new Error("Invalid cookie jar, please set cookies through your jar rather than unirest.")
  }

  return this
}