How to use the insomnia-cookies.jarFromCookies function in insomnia-cookies

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

github Kong / insomnia / packages / insomnia-app / app / network / network.js View on Github external
// Collect various things
        const httpVersion = lastCurlHeadersObject.version || '';
        const statusCode = lastCurlHeadersObject.code || -1;
        const statusMessage = lastCurlHeadersObject.reason || '';

        // Collect the headers
        const headers = lastCurlHeadersObject.headers;

        // Calculate the content type
        const contentTypeHeader = getContentTypeHeader(headers);
        const contentType = contentTypeHeader ? contentTypeHeader.value : '';

        // Update Cookie Jar
        let currentUrl = finalUrl;
        let setCookieStrings: Array<string> = [];
        const jar = jarFromCookies(renderedRequest.cookieJar.cookies);

        for (const { headers } of allCurlHeadersObjects) {
          // Collect Set-Cookie headers
          const setCookieHeaders = getSetCookieHeaders(headers);
          setCookieStrings = [...setCookieStrings, ...setCookieHeaders.map(h => h.value)];

          // Pull out new URL if there is a redirect
          const newLocation = getLocationHeader(headers);
          if (newLocation !== null) {
            currentUrl = urlResolve(currentUrl, newLocation.value);
          }
        }

        // Update jar with Set-Cookie headers
        for (const setCookieStr of setCookieStrings) {
          try {
github Kong / insomnia / plugins / insomnia-plugin-cookie-jar / __tests__ / index.js View on Github external
it('should get cookie by name', async () => {
      const jar = jarFromCookies([]);
      jar.setCookieSync(
        [
          'foo=bar',
          'path=/',
          'domain=.insomnia.rest',
          'HttpOnly Cache-Control: public, no-cache',
        ].join('; '),
        'https://insomnia.rest',
      );

      const cookies = await cookiesFromJar(jar);
      const requests = [{ _id: 'req_1', parameters: [], url: 'https://insomnia.rest/foo/bar' }];
      const jars = [{ _id: 'jar_1', parentId: 'wrk_1', cookies }];
      const context = _getTestContext([{ _id: 'wrk_1' }], requests, jars);
      try {
        await tag.run(context, 'https://insomnia.rest', 'bar');
github Kong / insomnia / plugins / insomnia-plugin-cookie-jar / index.js View on Github external
return new Promise((resolve, reject) => {
    const jar = jarFromCookies(cookieJar.cookies);

    jar.getCookies(url, {}, (err, cookies) => {
      if (err) {
        console.warn(`Failed to find cookie for ${url}`, err);
      }

      if (!cookies || cookies.length === 0) {
        console.log(cookies);
        reject(new Error(`No cookies in store for url "${url}"`));
      }

      const cookie = cookies.find(cookie => cookie.key === name);
      if (!cookie) {
        const names = cookies.map(c => `"${c.key}"`).join(',\n\t');
        throw new Error(
          `No cookie with name "${name}".\nChoices are [\n\t${names}\n] for url "${url}"`,
github Kong / insomnia / plugins / insomnia-plugin-request / index.js View on Github external
return new Promise((resolve, reject) => {
    const jar = jarFromCookies(cookieJar.cookies);

    jar.getCookies(url, {}, (err, cookies) => {
      if (err) {
        console.warn(`Failed to find cookie for ${url}`, err);
      }

      if (!cookies || cookies.length === 0) {
        reject(new Error(`No cookies in store for url "${url}"`));
      }

      const cookie = cookies.find(cookie => cookie.key === name);
      if (!cookie) {
        const names = cookies.map(c => `"${c.key}"`).join(',\n\t');
        throw new Error(
          `No cookie with name "${name}".\nChoices are [\n\t${names}\n] for url "${url}"`,
        );
github Kong / insomnia / packages / insomnia-app / app / common / har.js View on Github external
function getRequestCookies(renderedRequest: RenderedRequest): Array<HarCookie> {
  const jar = jarFromCookies(renderedRequest.cookieJar.cookies);
  const domainCookies = jar.getCookiesSync(renderedRequest.url);
  return domainCookies.map(mapCookie);
}

insomnia-cookies

Cookie utilities

MIT
Latest version published 1 month ago

Package Health Score

90 / 100
Full package analysis

Similar packages