diff --git a/src/gatherers/webpagetest.js b/src/gatherers/webpagetest.js index cc49722..d4f0936 100644 --- a/src/gatherers/webpagetest.js +++ b/src/gatherers/webpagetest.js @@ -180,6 +180,8 @@ class WebPageTestGatherer extends Gatherer { urlParams.push(key + '=' + params[key]); }); let url = this.runApiEndpoint + '?' + urlParams.join('&'); + options.headers = options.headers || {}; + options.headers['X-WPT-API-KEY'] = this.apiKey; let response, body = {}, statusText; if (this.apiKey === 'TEST_APIKEY') { @@ -193,7 +195,7 @@ class WebPageTestGatherer extends Gatherer { } else { if (this.debug) console.log('WPTGatherer::run\n', url); - response = this.apiHandler.fetch(url); + response = this.apiHandler.fetch(url, options); if (this.debug) { console.log('WPTGatherer::run API response: \n', response); @@ -298,7 +300,7 @@ class WebPageTestGatherer extends Gatherer { let url = this.resultApiEndpoint + '?' + urlParams.join('&'); if (this.debug) console.log('WPTGatherer::retrieve\n', url); - let response = this.apiHandler.fetch(url); + let response = this.apiHandler.fetch(url, options); if (response.statusCode >= 400) { return { diff --git a/src/helpers/appscript-helper.js b/src/helpers/appscript-helper.js index 5c3e235..8cac7e2 100644 --- a/src/helpers/appscript-helper.js +++ b/src/helpers/appscript-helper.js @@ -17,13 +17,13 @@ const ApiHandler = require('./api-handler'); class AppScriptApiHandler extends ApiHandler { - fetch(url) { - return this.get(url); + fetch(url, options) { + return this.get(url, options); } - get(url) { + get(url, options) { try { - var response = UrlFetchApp.fetch(url); + var response = UrlFetchApp.fetch(url, options); return { statusCode: response.getResponseCode(), body: response.getContentText(),