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:
parent
7dddc12dad
commit
426fb42bca
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue