From efa33c37b315eed1ed6efde8ee6064383dea37d8 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 24 Jul 2017 23:35:10 -0700 Subject: [PATCH] Remove page.httpHeaders() getter Remove the page.httpHeaders() method since it always returns the last value of page.setHTTPHeaders(). References #115. --- docs/api.md | 4 ---- lib/Page.js | 7 ------- phantom_shim/WebPage.js | 4 +++- test/test.js | 2 -- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/docs/api.md b/docs/api.md index fdec1c66..021e0091 100644 --- a/docs/api.md +++ b/docs/api.md @@ -38,7 +38,6 @@ + [page.goBack(options)](#pagegobackoptions) + [page.goForward(options)](#pagegoforwardoptions) + [page.hover(selector)](#pagehoverselector) - + [page.httpHeaders()](#pagehttpheaders) + [page.injectFile(filePath)](#pageinjectfilefilepath) + [page.keyboard](#pagekeyboard) + [page.mainFrame()](#pagemainframe) @@ -408,9 +407,6 @@ Navigate to the next page in history. - `selector` <[string]> A query selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered. - returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully hovered. Promise gets rejected if there's no element matching `selector`. -#### page.httpHeaders() -- returns: <[Object]> Key-value set of additional http headers which will be sent with every request. - #### page.injectFile(filePath) - `filePath` <[string]> Path to the javascript file to be injected into page. - returns: <[Promise]> Promise which resolves when file gets successfully evaluated in page. diff --git a/lib/Page.js b/lib/Page.js index 674360c1..44910cb5 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -189,13 +189,6 @@ class Page extends EventEmitter { return this._networkManager.setHTTPHeaders(headers); } - /** - * @return {!Object} - */ - httpHeaders() { - return this._networkManager.httpHeaders(); - } - /** * @param {string} userAgent * @return {!Promise} diff --git a/phantom_shim/WebPage.js b/phantom_shim/WebPage.js index 723a5e70..a4851c4e 100644 --- a/phantom_shim/WebPage.js +++ b/phantom_shim/WebPage.js @@ -48,6 +48,7 @@ class WebPage { this.onResourceReceived = null; this._onInitialized = undefined; this._deferEvaluate = false; + this._customHeaders = {}; this._currentFrame = this._page.mainFrame(); @@ -275,13 +276,14 @@ class WebPage { * @return {!Object} */ get customHeaders() { - return this._page.httpHeaders(); + return this._customHeaders; } /** * @param {!Object} value */ set customHeaders(value) { + this._customHeaders = value; await(this._page.setHTTPHeaders(value)); } diff --git a/test/test.js b/test/test.js index dccf0d38..0915b5bb 100644 --- a/test/test.js +++ b/test/test.js @@ -1003,9 +1003,7 @@ describe('Puppeteer', function() { }); describe('Page.setHTTPHeaders', function() { it('should work', SX(async function() { - expect(page.httpHeaders()).toEqual({}); page.setHTTPHeaders({'foo': 'bar'}); - expect(page.httpHeaders()).toEqual({'foo': 'bar'}); page.navigate(EMPTY_PAGE); let request = await server.waitForRequest('/empty.html'); expect(request.headers['foo']).toBe('bar');