Socket
Socket
Sign inDemoInstall

httpheaderprovider

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpheaderprovider - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

test/test-connect-remote-header.js

2

.vscode/launch.json

@@ -11,3 +11,3 @@ {

"name": "Launch Program",
"program": "${workspaceRoot}/test/test-connect-header.js",
"program": "${workspaceRoot}/test/test-connect-remote-header.js",
"cwd": "${workspaceRoot}"

@@ -14,0 +14,0 @@ },

@@ -47,23 +47,10 @@ /* HttpHeaderProvider

HttpHeaderProvider.prototype.send = function _send (payload) {
debug("Request: %s", JSON.stringify(payload));
var result = Web3.providers.HttpProvider.prototype.send.call(this, payload);
debug("Result: %s", JSON.stringify(result));
return result;
};
//the 'classy way' in es2015+
/*
class HttpHeaderProvider extends Web3.providers.HttpProvider {
constructor(host) {
debug('in prv constructor');
super(host);
}
prepareRequest(async) {
debug('in prepare');
var request = super.prepareRequest(async);
return request;
}
}
*/
module.exports = HttpHeaderProvider;

@@ -70,0 +57,0 @@

{
"name": "httpheaderprovider",
"version": "0.3.3",
"version": "0.3.4",
"description": "Replacement for HttpProvider from web3.js which allows headers to be set",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -6,2 +6,85 @@ # HttpHeaderProvider - A Replacement Web3.js HttpProvider supporting custom HTTP Headers

## Using
First you need to grab the `npm` package and then reference it.
```bash
npm install --save httpheaderprovider
```
### Debug Mode
The module supports emitting debug information by adding an environment variable:
```bash
export DEBUG=ethereumex:httpheaderprovider
# windows cmd
SET DEBUG=ethereumex:httpheaderprovider
# posh
$env:DEBUG="ethereumex:httpheaderprovider"
```
#### Debug messages
Once debug is enabled you see things like:
```bash
talking to remote Geth on https://<yourAPI>.azure-api.net/geth/
ethereumex:httpheaderprovider constructor:begin +0ms
ethereumex:httpheaderprovider constructor:end +2ms
ethereumex:httpheaderprovider Request: {"jsonrpc":"2.0","id":1,"method":"web3_clientVersion","params":[]} +1ms
ethereumex:httpheaderprovider prepareRequest:begin +1ms
ethereumex:httpheaderprovider setting headers +13ms
ethereumex:httpheaderprovider prepareRequest:end +0ms
ethereumex:httpheaderprovider Result: {"jsonrpc":"2.0","id":1,"result":"Geth/v1.5.4-stable-b70acf3c/linux/go1.7.3"} +371ms
ethereum client info: Geth/v1.5.4-stable-b70acf3c/linux/go1.7.3
ethereumex:httpheaderprovider Request: {"jsonrpc":"2.0","id":2,"method":"net_peerCount","params":[]} +1ms
ethereumex:httpheaderprovider prepareRequest:begin +0ms
ethereumex:httpheaderprovider setting headers +1ms
ethereumex:httpheaderprovider prepareRequest:end +0ms
ethereumex:httpheaderprovider Result: {"jsonrpc":"2.0","id":2,"result":"0x19"} +249ms
Peer Count: 25
ethereumex:httpheaderprovider Request: {"jsonrpc":"2.0","id":3,"method":"eth_coinbase","params":[]} +3ms
ethereumex:httpheaderprovider prepareRequest:begin +0ms
ethereumex:httpheaderprovider setting headers +0ms
ethereumex:httpheaderprovider prepareRequest:end +0ms
ethereumex:httpheaderprovider Result: {"jsonrpc":"2.0","id":3,"result":"0x13015840b5b4641f3ad441e36ec428d7a1c9934c"} +431ms
web3.eth.coinbase: 0x13015840b5b4641f3ad441e36ec428d7a1c9934c
ethereumex:httpheaderprovider Request: {"jsonrpc":"2.0","id":4,"method":"eth_getBalance","params":["0x13015840b5b4641f3ad441e36ec428d7a1c9934c","latest"]} +2ms
ethereumex:httpheaderprovider prepareRequest:begin +0ms
ethereumex:httpheaderprovider setting headers +0ms
ethereumex:httpheaderprovider prepareRequest:end +1ms
ethereumex:httpheaderprovider Result: {"jsonrpc":"2.0","id":4,"result":"0x8cf23f909c0fa000"} +277ms
web3.eth.getBalance(coinbase) 10156250000000000000
```
### Adding to your web3.js project
In your JavaScript project instead of create an instance of the `web3.providers.HttpProvider` in place, create an instance of `HttpHeaderProvider` with the same parameters along with a object that is a key/value property object.
```javascript
var Web3 = require('web3');
var web3 = new Web3();
var HttpHeaderProvider = require('httpheaderprovider');
var headers = {
"Ocp-Apim-Subscription-Key": "mykeyfromtheapiportal",
"header2": "foobar"
}
var provider = new HttpHeaderProvider('https://scicoria.azure-api.net', headers);
web3.setProvider(provider);
var coinbase = web3.eth.coinbase;
console.log(coinbase);
var balance = web3.eth.getBalance(coinbase);
console.log(balance.toString(10));
```
## Purpose

@@ -12,2 +95,4 @@ The [`JSON-RPC`](https://github.com/ethereum/wiki/wiki/JSON-RPC) endpoint on an [Ethereum client](https://geth.ethereum.org) provides no authentication or authorization boundary. All validation happens after the client receives the reqeust and processes it, and true validation is based upon the presence of a signed transaction or not.

Plus using a proxy that can add HTTPS and terminate it is nice as well. If the Get instance and the RPC client are distributed, this easily allows adding HTTPS to the transport.
### Microsoft Azure API Management

@@ -50,32 +135,1 @@ A reason to employ a Service such as [Azure API Management](https://azure.microsoft.com/en-us/services/api-management/) off-loads other resposibilities such as dealing with both Layer 3/4 and layer 7 DoS issues.

## Using
First you need to grab the `npm` package and then reference it.
```bash
npm install --save httpheaderprovider
```
In your JavaScript project instead of create an instance of the `web3.providers.HttpProvider` in place, create an instance of `HttpHeaderProvider` with the same parameters along with a object that is a key/value property object.
```javascript
var Web3 = require('web3');
var web3 = new Web3();
var HttpHeaderProvider = require('httpheaderprovider');
var headers = {
"Ocp-Apim-Subscription-Key": "mykeyfromtheapiportal",
"header2": "foobar"
}
var provider = new HttpHeaderProvider('https://scicoria.azure-api.net', headers);
web3.setProvider(provider);
var coinbase = web3.eth.coinbase;
console.log(coinbase);
var balance = web3.eth.getBalance(coinbase);
console.log(balance.toString(10));
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc