feat: Store cookies received in Runner execution (#2951)

This commit is contained in:
j-lebek 2024-09-03 17:42:54 +02:00 committed by GitHub
parent 2a93a6fa65
commit 5931f0bb4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -88,6 +88,22 @@ const getJsSandboxRuntime = (collection) => {
const protocolRegex = /^([-+\w]{1,25})(:?\/\/|:)/;
const saveCookies = (url, headers) => {
if (preferencesUtil.shouldStoreCookies()) {
let setCookieHeaders = [];
if (headers['set-cookie']) {
setCookieHeaders = Array.isArray(headers['set-cookie'])
? headers['set-cookie']
: [headers['set-cookie']];
for (let setCookieHeader of setCookieHeaders) {
if (typeof setCookieHeader === 'string' && setCookieHeader.length) {
addCookieToJar(setCookieHeader, url);
}
}
}
}
}
const configureRequest = async (
collectionUid,
request,
@ -590,17 +606,7 @@ const registerNetworkIpc = (mainWindow) => {
// save cookies
if (preferencesUtil.shouldStoreCookies()) {
let setCookieHeaders = [];
if (response.headers['set-cookie']) {
setCookieHeaders = Array.isArray(response.headers['set-cookie'])
? response.headers['set-cookie']
: [response.headers['set-cookie']];
for (let setCookieHeader of setCookieHeaders) {
if (typeof setCookieHeader === 'string' && setCookieHeader.length) {
addCookieToJar(setCookieHeader, request.url);
}
}
}
saveCookies(request.url, response.headers);
}
// send domain cookies to renderer
@ -1016,6 +1022,16 @@ const registerNetworkIpc = (mainWindow) => {
response.data = data;
response.responseTime = response.headers.get('request-duration');
// save cookies
if (preferencesUtil.shouldStoreCookies()) {
saveCookies(request.url, response.headers);
}
// send domain cookies to renderer
const domainsWithCookies = await getDomainsWithCookies();
mainWindow.webContents.send('main:cookies-update', safeParseJSON(safeStringifyJSON(domainsWithCookies)));
mainWindow.webContents.send('main:run-folder-event', {
type: 'response-received',
responseReceived: {