Skip to content

Commit

Permalink
added cookie xhr2
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Jun 27, 2018
1 parent c0e727e commit f98fe14
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
16 changes: 12 additions & 4 deletions packages/web3-providers-http/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/web3-providers-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"main": "src/index.js",
"dependencies": {
"web3-core-helpers": "1.0.0-beta.34",
"xhr2": "0.1.4"
"xhr2-cookies": "1.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/web3-providers-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

var errors = require('web3-core-helpers').errors;
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
Expand All @@ -42,6 +42,7 @@ HttpProvider.prototype._prepareRequest = function(){
request.open('POST', this.host, true);
request.setRequestHeader('Content-Type','application/json');
request.timeout = this.timeout && this.timeout !== 1 ? this.timeout : 0;
request.withCredentials = true;

if(this.headers) {
this.headers.forEach(function(header) {
Expand All @@ -63,7 +64,6 @@ HttpProvider.prototype.send = function (payload, callback) {
var _this = this;
var request = this._prepareRequest();


request.onreadystatechange = function() {
if (request.readyState === 4 && request.timeout !== 1) {
var result = request.responseText;
Expand Down
13 changes: 7 additions & 6 deletions packages/web3-providers-ws/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/helpers/FakeXHR2.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ FakeXHR2.prototype.send = function (payload) {
}
};

module.exports = FakeXHR2;
module.exports = {XMLHttpRequest: FakeXHR2};
2 changes: 1 addition & 1 deletion test/httpprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var SandboxedModule = require('sandboxed-module');
SandboxedModule.registerBuiltInSourceTransformer('istanbul');
var HttpProvider = SandboxedModule.require('../packages/web3-providers-http', {
requires: {
'xhr2': require('./helpers/FakeXHR2'),
'xhr2-cookies': require('./helpers/FakeXHR2'),
// 'xmlhttprequest': require('./helpers/FakeXMLHttpRequest')
},
singleOnly: true
Expand Down

0 comments on commit f98fe14

Please sign in to comment.