Tune the cookie handling to handle = in the cookie (#3473)

* Tune the cookie handling to handle = in the cookie

* fix path
This commit is contained in:
Peter Hedenskog 2021-10-08 18:43:36 +02:00 committed by GitHub
parent 7dddc12dad
commit 426fb42bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 13 deletions

View File

@ -5,6 +5,7 @@ const merge = require('lodash.merge');
const log = require('intel').getLogger('sitespeedio.plugin.crawler');
const Crawler = require('simplecrawler');
const throwIfMissing = require('../../support/util').throwIfMissing;
const toArray = require('../../support/util').toArray;
const defaultOptions = {
depth: 3
@ -47,20 +48,17 @@ module.exports = {
crawler.respectRobotsTxt = false;
}
function addCookie(cookie) {
const cookieSplit = cookie.split('=');
if (cookieSplit.length === 2) {
crawler.cookies.add(cookieSplit[0], cookieSplit[1]);
}
}
if (this.cookie) {
if (Array.isArray(this.cookie)) {
for (let e of this.cookie) {
addCookie(e);
}
} else if (typeof this.cookie === 'string') {
addCookie(this.cookie);
const cookies = toArray(this.cookie);
for (let cookieParts of cookies) {
const parts = new Array(
cookieParts.slice(0, cookieParts.indexOf('=')),
cookieParts.slice(
cookieParts.indexOf('=') + 1,
cookieParts.length
)
);
crawler.cookies.add(parts[0], parts[1]);
}
}