Skip to content

Commit

Permalink
fixed http provider
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Apr 19, 2018
1 parent e2c79ee commit c0e727e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion packages/web3-providers-http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ This will expose the `Web3HttpProvider` object on the window object.
// in node.js
var Web3HttpProvider = require('web3-providers-http');

var http = new Web3HttpProvider('http://localhost:8545');
var options = {
timeout: 20000, // milliseconds,
headers: [{name: 'Access-Control-Allow-Origin', value: '*'},{...}]
};
var http = new Web3HttpProvider('http://localhost:8545', options);
```


Expand Down
7 changes: 4 additions & 3 deletions packages/web3-providers-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ var XHR2 = require('xhr2'); // jshint ignore: line
/**
* HttpProvider should be used to send rpc calls over http
*/
var HttpProvider = function HttpProvider(host, timeout, headers) {
var HttpProvider = function HttpProvider(host, options) {
options = options || {};
this.host = host || 'http://localhost:8545';
this.timeout = timeout || 0;
this.timeout = options.timeout || 0;
this.headers = options.headers;
this.connected = false;
this.headers = headers;
};

HttpProvider.prototype._prepareRequest = function(){
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-providers-ws/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ if (typeof window !== 'undefined' && typeof window.WebSocket !== 'undefined') {
var url = require('url');
if (url.URL) {
// Use the new Node 6+ API for parsing URLs that supports username/password
var URL = url.URL;
var newURL = url.URL;
parseURL = function(url) {
return new URL(url);
return new newURL(url);
};
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/httpprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var HttpProvider = SandboxedModule.require('../packages/web3-providers-http', {
describe('web3-providers-http', function () {
describe('prepareRequest', function () {
it('should set request header', function () {
var provider = new HttpProvider('http://localhost:8545', 0 , [{name: 'Access-Control-Allow-Origin', value: '*'}]);
var provider = new HttpProvider('http://localhost:8545', {headers: [{name: 'Access-Control-Allow-Origin', value: '*'}]});
var result = provider._prepareRequest();

assert.equal(typeof result, 'object');
Expand Down

0 comments on commit c0e727e

Please sign in to comment.