From 50976c7f2986ae4ff3ad6f0c862fe87e00d0f474 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 15 Jun 2017 08:37:06 -0700 Subject: [PATCH] Implement Request.setHeader() method This patch implements Request.setHeader() method to override request headers. References #8. --- lib/Request.js | 9 ++++++--- third_party/phantomjs/test/module/webpage/add-header.js | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Request.js b/lib/Request.js index 03f18eb2d6f..f8797a9dcba 100644 --- a/lib/Request.js +++ b/lib/Request.js @@ -71,10 +71,13 @@ class Request { } /** - * @param {!Object} headers + * @param {string} key + * @param {string} value */ - setHeaders(headers) { - this._headersOverride = headers; + setHeader(key, value) { + if (!this._headersOverride) + this._headersOverride = Object.assign({}, this._headers); + this._headersOverride[key] = value; } /** diff --git a/third_party/phantomjs/test/module/webpage/add-header.js b/third_party/phantomjs/test/module/webpage/add-header.js index 5594f4e2834..46b70bb1b0e 100644 --- a/third_party/phantomjs/test/module/webpage/add-header.js +++ b/third_party/phantomjs/test/module/webpage/add-header.js @@ -1,4 +1,3 @@ -//! unsupported async_test(function () { var webpage = require('webpage');