Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 = [];
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 {
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');
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}"`,
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}"`,
);
function getRequestCookies(renderedRequest: RenderedRequest): Array {
const jar = jarFromCookies(renderedRequest.cookieJar.cookies);
const domainCookies = jar.getCookiesSync(renderedRequest.url);
return domainCookies.map(mapCookie);
}