Skip to content

Commit

Permalink
Fix (i think) header setting
Browse files Browse the repository at this point in the history
 🐿 v2.7.0
  • Loading branch information
adgad committed Mar 15, 2018
1 parent 010bc95 commit ee04b17
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/smoke/puppeteer-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const getUserTokens = require('./get-user-tokens');
const setSessionCookies = require('./set-session-cookies');
const { URL } = require('url');

const REDIRECT_CODES = [301, 302, 303, 307, 308];

Expand All @@ -17,6 +18,7 @@ class PuppeteerPage {
this.browser = null;
this.type = 'Chrome';
this.url = url;
this.host = options.host;

if(options.https) {
this.url = this.url.replace('http:', 'https:');
Expand Down Expand Up @@ -103,9 +105,16 @@ class PuppeteerPage {
const overrides = {};
const url = interceptedRequest.url();

//only apply the request headers to the initial URL request, and any whitelisted paths
if(this.requestHeaderPaths.find(path => new RegExp(path).test(url))) {
overrides.headers = Object.assign({}, this.requestHeaders);
// For user requests, only apply the request headers to the initial URL request, and any whitelisted paths
if(this.user) {
if(this.requestHeaderPaths.find(path => new RegExp(path).test(url))) {
overrides.headers = Object.assign({}, this.requestHeaders);
}
} else {
//Otherwise apply headers for any URls with the same host
if(new URL(url).host === new URL(this.url).host) {
overrides.headers = Object.assign({}, this.requestHeaders);
}
}

if (!interceptionHandled) {
Expand Down

0 comments on commit ee04b17

Please sign in to comment.