Socket
Socket
Sign inDemoInstall

browsermob-proxy-api

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browsermob-proxy-api - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

77

index.js
var http = require('http');
function parameterize(cfg) {
var params = [];
for (var key in cfg) {
params.push(key + '=' + encodeURIComponent(cfg[key]));
}
return params.join('&');
}
var MobProxy = function(cfg) {

@@ -7,105 +16,95 @@ this.host = (cfg && cfg.host) ? cfg.host : 'localhost';

this.debug = (cfg && cfg.debug) ? cfg.debug : false;
}
};
MobProxy.prototype = {
getProxyList: function(callback) {
this.call('GET', '/proxy', null, callback);
this._call('GET', '/proxy', null, callback);
},
startPort: function(port, callback) {
this.call('POST', '/proxy', 'port=' + port, callback);
this._call('POST', '/proxy', 'port=' + port, callback);
},
stopPort: function(port, callback) {
this.call('DELETE', '/proxy/' + port, null, callback);
this._call('DELETE', '/proxy/' + port, null, callback);
},
createHAR: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/har', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/har', parameterize(cfg), callback);
},
startNewPage: function(port, pageRef, callback) {
this.call('PUT', '/proxy/' + port + '/har/pageRef', pageRef ? pageRef : '', callback);
this._call('PUT', '/proxy/' + port + '/har/pageRef', pageRef ? pageRef : '', callback);
},
getHAR: function(port, callback) {
this.call('GET', '/proxy/' + port + '/har', null, callback);
this._call('GET', '/proxy/' + port + '/har', null, callback);
},
limit: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/limit', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/limit', parameterize(cfg), callback);
},
addURLWhiteList: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/whitelist', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/whitelist', parameterize(cfg), callback);
},
clearURLWhiteList: function(port, callback) {
this.call('DELETE', '/proxy/' + port + '/whitelist', null, callback);
this._call('DELETE', '/proxy/' + port + '/whitelist', null, callback);
},
addURLBlackList: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/blacklist', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/blacklist', parameterize(cfg), callback);
},
clearURLBlackList: function(port, callback) {
this.call('DELETE', '/proxy/' + port + '/blacklist', null, callback);
this._call('DELETE', '/proxy/' + port + '/blacklist', null, callback);
},
setHeaders: function(port, json, callback) {
this.call('POST', '/proxy/' + port + '/headers', json, callback, true);
this._call('POST', '/proxy/' + port + '/headers', json, callback, true);
},
setDNSLookupOverride: function(port, json, callback) {
this.call('POST', '/proxy/' + port + '/hosts', json, callback, true);
this._call('POST', '/proxy/' + port + '/hosts', json, callback, true);
},
setAuthentication: function(port, domain, json, callback) {
this.call('POST', '/proxy/' + port + '/auth/basic/' + domain, json, callback, true);
this._call('POST', '/proxy/' + port + '/auth/basic/' + domain, json, callback, true);
},
setWaitPeriod: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/wait', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/wait', parameterize(cfg), callback);
},
setTimeouts: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/timeout', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/timeout', parameterize(cfg), callback);
},
addURLRedirect: function(port, cfg, callback) {
this.call('PUT', '/proxy/' + port + '/rewrite', this.parameterize(cfg), callback);
this._call('PUT', '/proxy/' + port + '/rewrite', parameterize(cfg), callback);
},
removeAllURLRedirects: function(port, callback) {
this.call('DELETE', '/proxy/' + port + '/rewrite', null, callback);
this._call('DELETE', '/proxy/' + port + '/rewrite', null, callback);
},
setRetryCount: function(port, retryCount, callback) {
this.call('PUT', '/proxy/' + port + '/retry', 'retryCount=' + retryCount, callback);
this._call('PUT', '/proxy/' + port + '/retry', 'retryCount=' + retryCount, callback);
},
clearDNSCache: function(port, callback) {
this.call('DELETE', '/proxy/' + port + '/dns/cache', null, callback);
this._call('DELETE', '/proxy/' + port + '/dns/cache', null, callback);
},
addRequestInterceptor: function(port, payload, callback) {
this.call('POST', '/proxy/' + port + '/interceptor/request', payload, callback);
this._call('POST', '/proxy/' + port + '/interceptor/request', payload, callback);
},
addResponseInterceptor: function(port, payload, callback) {
this.call('POST', '/proxy/' + port + '/interceptor/response', payload, callback);
this._call('POST', '/proxy/' + port + '/interceptor/response', payload, callback);
},
parameterize: function(cfg) {
var params = [];
for(var key in cfg) {
params.push(key + '=' + encodeURIComponent(cfg[key]));
}
return params.join('&');
},
call: function(method, url, data, callback, isJson) {
_call: function(method, url, data, callback, isJson) {
var self = this;
var contentType = isJson ? 'application/json' : 'application/x-www-form-urlencoded';
var contentType = isJson ? 'application/json' : 'application/x-www-form-urlencoded';
var options = {

@@ -124,3 +123,3 @@ host: this.host,

var resp = '';
response.on('data', function(chunk) {
response.on('data', function(chunk) {
resp += chunk;

@@ -131,5 +130,5 @@ });

if(self.debug) { console.log(resp); }
if(callback != undefined) { callback(null, resp); }
if(callback !== undefined) { callback(null, resp); }
});
}
};

@@ -141,4 +140,4 @@ var request = http.request(options, respCallback);

}
};
module.exports = MobProxy;
{
"name": "browsermob-proxy-api",
"version": "0.1.4",
"version": "0.1.5",
"description": "NodeJS bindings for controlling a browsermob-proxy instance (creating ports, HARs, etc)",

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

@@ -11,3 +11,3 @@ # Node BrowserMob Proxy API

For the specifics of the REST API used by BrowserMob Proxy, please see [documentation](https://github.com/lightbody/browsermob-proxy/blob/master/README.md).
For the specifics of the REST API used by BrowserMob Proxy, please see their [documentation](https://github.com/lightbody/browsermob-proxy/blob/master/README.md).

@@ -14,0 +14,0 @@ ### Examples

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