From 44023b7967660e07f205cabf3e0cb513ae5ab820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Wed, 20 Jun 2018 18:01:41 +0100 Subject: [PATCH 1/2] Add cookie support for HTTP provider --- lib/web3/httpprovider.js | 4 +++- package.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/web3/httpprovider.js b/lib/web3/httpprovider.js index e12ebc0a819..9a6dcfe85c5 100644 --- a/lib/web3/httpprovider.js +++ b/lib/web3/httpprovider.js @@ -34,7 +34,7 @@ if (typeof window !== 'undefined' && window.XMLHttpRequest) { XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line } -var XHR2 = require('xhr2'); // jshint ignore: line +var XHR2 = require('xhr2-cookies').XMLHttpRequest; // jshint ignore: line /** * HttpProvider should be used to send rpc calls over http @@ -60,8 +60,10 @@ HttpProvider.prototype.prepareRequest = function (async) { if (async) { request = new XHR2(); request.timeout = this.timeout; + request.withCredentials = true; } else { request = new XMLHttpRequest(); + request.withCredentials = true; } request.open('POST', this.host, async); diff --git a/package.json b/package.json index 4419a8023fb..0269eccaf3d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git", "crypto-js": "^3.1.4", "utf8": "^2.1.1", - "xhr2": "*", + "xhr2-cookies": "^1.1.0", "xmlhttprequest": "*" }, "browser": { From 8db48e1e16715196eec72d1365f4f8426ab8badf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Wed, 27 Jun 2018 10:04:02 +0100 Subject: [PATCH 2/2] Simplify code --- lib/web3/httpprovider.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/web3/httpprovider.js b/lib/web3/httpprovider.js index 9a6dcfe85c5..71e2cd8c2ee 100644 --- a/lib/web3/httpprovider.js +++ b/lib/web3/httpprovider.js @@ -60,11 +60,10 @@ HttpProvider.prototype.prepareRequest = function (async) { if (async) { request = new XHR2(); request.timeout = this.timeout; - request.withCredentials = true; } else { request = new XMLHttpRequest(); - request.withCredentials = true; } + request.withCredentials = true; request.open('POST', this.host, async); if (this.user && this.password) {