browsermob-proxy-api-client 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -2
- package/dist/index.d.ts +126 -0
- package/dist/index.js +233 -89
- package/dist/index.js.map +1 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
# BrowserMob Proxy API Client
|
|
2
|
-
Client library
|
|
2
|
+
Client library for [BrowserMob Proxy] API
|
|
3
3
|
|
|
4
|
-
[
|
|
4
|
+
Refer to [REST API] section of BrowserMob Proxy documentation for detailed information
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.org/package/browsermob-proxy-api-client)
|
|
7
|
+
[](https://packagephobia.now.sh/result?p=browsermob-proxy-api-client)
|
|
8
|
+
[](https://bundlephobia.com/package/browsermob-proxy-api-client@latest)
|
|
9
|
+
[](https://npm-stat.com/charts.html?package=browsermob-proxy-api-client)
|
|
10
|
+
[](https://snyk.io/test/npm/browsermob-proxy-api-client)
|
|
11
|
+
|
|
12
|
+
## Installing
|
|
13
|
+
|
|
14
|
+
Using npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
$ npm install browsermob-proxy-api-client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Using yarn:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ yarn add browsermob-proxy-api-client
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Example
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import BrowserMobProxyAPIClient from 'browsermob-proxy-api-client';
|
|
30
|
+
|
|
31
|
+
const proxy = new BrowserMobProxyAPIClient('localhost', '8080');
|
|
32
|
+
const port = await proxy.start();
|
|
33
|
+
if (port) {
|
|
34
|
+
try {
|
|
35
|
+
await proxy.startHar(port);
|
|
36
|
+
// exec `curl google.com --proxy localhost:${port}`
|
|
37
|
+
const har = await proxy.getHar(port);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.error(e);
|
|
40
|
+
} finally {
|
|
41
|
+
await proxy.stop(port);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
[BrowserMob Proxy]: https://github.com/lightbody/browsermob-proxy
|
|
47
|
+
[REST API]: https://github.com/lightbody/browsermob-proxy#rest-api
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RequestOptions } from 'http';
|
|
3
|
+
import { Har } from 'har-format';
|
|
4
|
+
import { BandwidthLimitsResponse, BlacklistItem, NewHarPageArgs, ProxyList, SetBandwidthLimitArgs, SetBlacklistArgs, SetRetryCountArgs, SetRewriteArgs, SetTimeoutsArgs, SetWhitelistArgs, StartHarArgs, StartProxyArgs, WaitArgs } from './typings/proxy';
|
|
5
|
+
declare enum Method {
|
|
6
|
+
GET = "GET",
|
|
7
|
+
POST = "POST",
|
|
8
|
+
PUT = "PUT",
|
|
9
|
+
DELETE = "DELETE"
|
|
10
|
+
}
|
|
11
|
+
export default class BrowserMobProxyAPIClient {
|
|
12
|
+
readonly host: string;
|
|
13
|
+
readonly port: number;
|
|
14
|
+
constructor(host?: string, port?: number);
|
|
15
|
+
protected httpRequest(options: RequestOptions, payload?: string): Promise<string>;
|
|
16
|
+
protected httpRequestWithArgs(path?: string, method?: Method, args?: Record<string, string | number | boolean>): Promise<string>;
|
|
17
|
+
/***
|
|
18
|
+
* Get a list of ports attached to ProxyServer instances managed by ProxyManager
|
|
19
|
+
*/
|
|
20
|
+
getProxyList(): Promise<ProxyList>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new proxy to run requests off of
|
|
23
|
+
*/
|
|
24
|
+
start(args?: StartProxyArgs): Promise<number | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Shuts down the proxy and closes the port.
|
|
27
|
+
*/
|
|
28
|
+
stop(port: number): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new HAR attached to the proxy
|
|
31
|
+
* returns the HAR content if there was a previous HAR
|
|
32
|
+
*/
|
|
33
|
+
startHar(port: number, args?: StartHarArgs): Promise<Har | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Starts a new page on the existing HAR
|
|
36
|
+
*/
|
|
37
|
+
newHarPage(port: number, args?: NewHarPageArgs): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the JSON/HAR content representing all the HTTP traffic passed through the proxy
|
|
40
|
+
* provided you have already created the HAR with this.startHar
|
|
41
|
+
*/
|
|
42
|
+
getHar(port: number): Promise<Har | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Get whitelisted items
|
|
45
|
+
*/
|
|
46
|
+
getWhitelist(port: number): Promise<string[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Sets a list of URL patterns to whitelist
|
|
49
|
+
*/
|
|
50
|
+
setWhitelist(port: number, args: SetWhitelistArgs): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Clears all URL patterns from the whitelist
|
|
53
|
+
*/
|
|
54
|
+
clearWhitelist(port: number): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get blacklisted items
|
|
57
|
+
*/
|
|
58
|
+
getBlacklist(port: number): Promise<BlacklistItem[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Set a URL to blacklist
|
|
61
|
+
*/
|
|
62
|
+
setBlacklist(port: number, args: SetBlacklistArgs): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Clears all URL patterns from the blacklist
|
|
65
|
+
*/
|
|
66
|
+
clearBlacklist(port: number): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Limit the bandwidth through the proxy
|
|
69
|
+
*/
|
|
70
|
+
setBandwidthLimit(port: number, args?: SetBandwidthLimitArgs): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Displays the amount of data remaining to be uploaded/downloaded until the limit is reached
|
|
73
|
+
*/
|
|
74
|
+
getBandwidthLimit(port: number): Promise<BandwidthLimitsResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Set and override HTTP Request headers
|
|
77
|
+
* Key is a header name (such as "User-Agent") and value is a value of HTTP header (such as "BrowserMob-Agent")
|
|
78
|
+
*/
|
|
79
|
+
setRequestHeaders(port: number, headers: Record<string, string>): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Overrides normal DNS lookups and remaps the given hosts with the associated IP address
|
|
82
|
+
* Key is a host name (such as "example.com") and value is the IP address (such as "1.2.3.4")
|
|
83
|
+
*/
|
|
84
|
+
setHosts(port: number, hosts: Record<string, string>): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Set username and passwords to be sent for requests on a specific domain that are protected by Basic Authentication
|
|
87
|
+
*/
|
|
88
|
+
setBasicAuth(port: number, domain: string, username: string, password: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Wait till all request are being made
|
|
91
|
+
*/
|
|
92
|
+
wait(port: number, args: WaitArgs): Promise<unknown>;
|
|
93
|
+
/**
|
|
94
|
+
* Handles different proxy timeouts
|
|
95
|
+
*/
|
|
96
|
+
setTimeouts(port: number, timeouts: SetTimeoutsArgs): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Redirecting URLs
|
|
99
|
+
*/
|
|
100
|
+
setRewrite(port: number, args: SetRewriteArgs): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Removes all URL redirection rules currently in effect
|
|
103
|
+
*/
|
|
104
|
+
clearRewrites(port: number): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Set retry count
|
|
107
|
+
*/
|
|
108
|
+
setRetryCount(port: number, args: SetRetryCountArgs): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Empties the DNS cache
|
|
111
|
+
*/
|
|
112
|
+
clearDNSCache(port: number): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Set request interceptor
|
|
115
|
+
* example: await proxy.setRequestInterceptor(port, "request.headers().remove('User-Agent'); request.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');");
|
|
116
|
+
* @see https://github.com/lightbody/browsermob-proxy#rest-api-interceptors-with-littleproxy
|
|
117
|
+
*/
|
|
118
|
+
setRequestInterceptor(port: number, interceptor: string): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Set response interceptor
|
|
121
|
+
* example: await proxy.setResponseInterceptor(port, "response.headers().remove('User-Agent'); response.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');");
|
|
122
|
+
* @see https://github.com/lightbody/browsermob-proxy#rest-api-interceptors-with-littleproxy
|
|
123
|
+
*/
|
|
124
|
+
setResponseInterceptor(port: number, interceptor: string): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,102 +1,246 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
exports.__esModule = true;
|
|
42
|
-
var http_1 = __importDefault(require("http"));
|
|
43
|
-
var BMPClient = /** @class */ (function () {
|
|
44
|
-
function BMPClient(host, port) {
|
|
45
|
-
if (host === void 0) { host = 'localhost'; }
|
|
46
|
-
if (port === void 0) { port = 8080; }
|
|
1
|
+
import http from 'http';
|
|
2
|
+
var Method;
|
|
3
|
+
(function (Method) {
|
|
4
|
+
Method["GET"] = "GET";
|
|
5
|
+
Method["POST"] = "POST";
|
|
6
|
+
Method["PUT"] = "PUT";
|
|
7
|
+
Method["DELETE"] = "DELETE";
|
|
8
|
+
})(Method || (Method = {}));
|
|
9
|
+
export default class BrowserMobProxyAPIClient {
|
|
10
|
+
constructor(host = 'localhost', port = 8080) {
|
|
47
11
|
this.host = host;
|
|
48
12
|
this.port = port;
|
|
49
13
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
var req = http_1["default"].request({
|
|
62
|
-
path: path,
|
|
63
|
-
method: method,
|
|
64
|
-
host: _this.host,
|
|
65
|
-
port: _this.port,
|
|
66
|
-
headers: headers
|
|
67
|
-
}, function (res) {
|
|
68
|
-
var data = [];
|
|
69
|
-
res.on('data', function (chunk) { return data.push(chunk); });
|
|
70
|
-
res.on('end', function () {
|
|
14
|
+
httpRequest(options, payload = '') {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const req = http.request({
|
|
17
|
+
host: this.host,
|
|
18
|
+
port: this.port,
|
|
19
|
+
...options,
|
|
20
|
+
}, res => {
|
|
21
|
+
const data = [];
|
|
22
|
+
res.on('data', chunk => data.push(chunk));
|
|
23
|
+
res.on('end', () => {
|
|
71
24
|
resolve(data.join());
|
|
72
25
|
});
|
|
73
26
|
});
|
|
74
|
-
req.on('error',
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
Object.entries(args).forEach(function (arg) { return params_1.set(arg[0], String(arg[1])); });
|
|
78
|
-
req.write(params_1.toString());
|
|
27
|
+
req.on('error', error => reject(error));
|
|
28
|
+
if (payload) {
|
|
29
|
+
req.write(payload);
|
|
79
30
|
}
|
|
80
31
|
req.end();
|
|
81
32
|
});
|
|
82
|
-
}
|
|
33
|
+
}
|
|
34
|
+
httpRequestWithArgs(path = '/', method = Method.GET, args = {}) {
|
|
35
|
+
const headers = {};
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
if ([Method.POST, Method.PUT].includes(method) && Object.entries(args).length) {
|
|
38
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
39
|
+
Object.entries(args).forEach(arg => params.set(arg[0], String(arg[1])));
|
|
40
|
+
}
|
|
41
|
+
return this.httpRequest({
|
|
42
|
+
path,
|
|
43
|
+
method,
|
|
44
|
+
headers,
|
|
45
|
+
}, params.toString());
|
|
46
|
+
}
|
|
83
47
|
/***
|
|
84
48
|
* Get a list of ports attached to ProxyServer instances managed by ProxyManager
|
|
85
49
|
*/
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
50
|
+
async getProxyList() {
|
|
51
|
+
return JSON.parse(await this.httpRequestWithArgs('/proxy', Method.GET));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new proxy to run requests off of
|
|
55
|
+
*/
|
|
56
|
+
async start(args = {}) {
|
|
57
|
+
const res = await this.httpRequestWithArgs('/proxy', Method.POST, { ...args });
|
|
58
|
+
const { port } = JSON.parse(res);
|
|
59
|
+
return port || null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Shuts down the proxy and closes the port.
|
|
63
|
+
*/
|
|
64
|
+
async stop(port) {
|
|
65
|
+
await this.httpRequestWithArgs(`/proxy/${port}`, Method.DELETE);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new HAR attached to the proxy
|
|
69
|
+
* returns the HAR content if there was a previous HAR
|
|
70
|
+
*/
|
|
71
|
+
async startHar(port, args = {}) {
|
|
72
|
+
const res = await this.httpRequestWithArgs(`/proxy/${port}/har`, Method.PUT, { ...args });
|
|
73
|
+
return res ? JSON.parse(res) : undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Starts a new page on the existing HAR
|
|
77
|
+
*/
|
|
78
|
+
async newHarPage(port, args = {}) {
|
|
79
|
+
await this.httpRequestWithArgs(`/proxy/${port}/har/pageRef`, Method.PUT, { ...args });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the JSON/HAR content representing all the HTTP traffic passed through the proxy
|
|
83
|
+
* provided you have already created the HAR with this.startHar
|
|
84
|
+
*/
|
|
85
|
+
async getHar(port) {
|
|
86
|
+
const res = await this.httpRequestWithArgs(`/proxy/${port}/har`, Method.GET);
|
|
87
|
+
return res ? JSON.parse(res) : undefined;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get whitelisted items
|
|
91
|
+
*/
|
|
92
|
+
async getWhitelist(port) {
|
|
93
|
+
return JSON.parse(await this.httpRequestWithArgs(`/proxy/${port}/whitelist`, Method.GET));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Sets a list of URL patterns to whitelist
|
|
97
|
+
*/
|
|
98
|
+
async setWhitelist(port, args) {
|
|
99
|
+
await this.httpRequestWithArgs(`/proxy/${port}/whitelist`, Method.PUT, { ...args });
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Clears all URL patterns from the whitelist
|
|
103
|
+
*/
|
|
104
|
+
async clearWhitelist(port) {
|
|
105
|
+
await this.httpRequestWithArgs(`/proxy/${port}/whitelist`, Method.DELETE);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get blacklisted items
|
|
109
|
+
*/
|
|
110
|
+
async getBlacklist(port) {
|
|
111
|
+
return JSON.parse(await this.httpRequestWithArgs(`/proxy/${port}/blacklist`, Method.GET));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Set a URL to blacklist
|
|
115
|
+
*/
|
|
116
|
+
async setBlacklist(port, args) {
|
|
117
|
+
await this.httpRequestWithArgs(`/proxy/${port}/blacklist`, Method.PUT, { ...args });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Clears all URL patterns from the blacklist
|
|
121
|
+
*/
|
|
122
|
+
async clearBlacklist(port) {
|
|
123
|
+
await this.httpRequestWithArgs(`/proxy/${port}/blacklist`, Method.DELETE);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Limit the bandwidth through the proxy
|
|
127
|
+
*/
|
|
128
|
+
async setBandwidthLimit(port, args = {}) {
|
|
129
|
+
await this.httpRequestWithArgs(`/proxy/${port}/limit`, Method.PUT, { ...args });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Displays the amount of data remaining to be uploaded/downloaded until the limit is reached
|
|
133
|
+
*/
|
|
134
|
+
async getBandwidthLimit(port) {
|
|
135
|
+
return JSON.parse(await this.httpRequestWithArgs(`/proxy/${port}/limit`, Method.GET));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Set and override HTTP Request headers
|
|
139
|
+
* Key is a header name (such as "User-Agent") and value is a value of HTTP header (such as "BrowserMob-Agent")
|
|
140
|
+
*/
|
|
141
|
+
async setRequestHeaders(port, headers) {
|
|
142
|
+
await this.httpRequest({
|
|
143
|
+
path: `/proxy/${port}/headers`,
|
|
144
|
+
method: Method.POST,
|
|
145
|
+
headers: {
|
|
146
|
+
'Content-Type': 'text/plain',
|
|
147
|
+
},
|
|
148
|
+
}, JSON.stringify(headers));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Overrides normal DNS lookups and remaps the given hosts with the associated IP address
|
|
152
|
+
* Key is a host name (such as "example.com") and value is the IP address (such as "1.2.3.4")
|
|
153
|
+
*/
|
|
154
|
+
async setHosts(port, hosts) {
|
|
155
|
+
await this.httpRequest({
|
|
156
|
+
path: `/proxy/${port}/hosts`,
|
|
157
|
+
method: Method.POST,
|
|
158
|
+
headers: {
|
|
159
|
+
'Content-Type': 'text/plain',
|
|
160
|
+
},
|
|
161
|
+
}, JSON.stringify(hosts));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Set username and passwords to be sent for requests on a specific domain that are protected by Basic Authentication
|
|
165
|
+
*/
|
|
166
|
+
async setBasicAuth(port, domain, username, password) {
|
|
167
|
+
await this.httpRequest({
|
|
168
|
+
path: `/proxy/${port}/auth/basic/${domain}`,
|
|
169
|
+
method: Method.POST,
|
|
170
|
+
headers: {
|
|
171
|
+
'Content-Type': 'text/plain',
|
|
172
|
+
},
|
|
173
|
+
}, JSON.stringify({ username, password }));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Wait till all request are being made
|
|
177
|
+
*/
|
|
178
|
+
async wait(port, args) {
|
|
179
|
+
return this.httpRequestWithArgs(`/proxy/${port}/wait`, Method.PUT, { ...args });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Handles different proxy timeouts
|
|
183
|
+
*/
|
|
184
|
+
async setTimeouts(port, timeouts) {
|
|
185
|
+
await this.httpRequest({
|
|
186
|
+
path: `/proxy/${port}/timeout`,
|
|
187
|
+
method: Method.PUT,
|
|
188
|
+
headers: {
|
|
189
|
+
'Content-Type': 'text/plain',
|
|
190
|
+
},
|
|
191
|
+
}, JSON.stringify(timeouts));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Redirecting URLs
|
|
195
|
+
*/
|
|
196
|
+
async setRewrite(port, args) {
|
|
197
|
+
await this.httpRequestWithArgs(`/proxy/${port}/rewrite`, Method.PUT, { ...args });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Removes all URL redirection rules currently in effect
|
|
201
|
+
*/
|
|
202
|
+
async clearRewrites(port) {
|
|
203
|
+
await this.httpRequestWithArgs(`/proxy/${port}/rewrite`, Method.DELETE);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Set retry count
|
|
207
|
+
*/
|
|
208
|
+
async setRetryCount(port, args) {
|
|
209
|
+
await this.httpRequestWithArgs(`/proxy/${port}/retry`, Method.PUT, { ...args });
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Empties the DNS cache
|
|
213
|
+
*/
|
|
214
|
+
async clearDNSCache(port) {
|
|
215
|
+
await this.httpRequestWithArgs(`/proxy/${port}/dns/cache`, Method.DELETE);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Set request interceptor
|
|
219
|
+
* example: await proxy.setRequestInterceptor(port, "request.headers().remove('User-Agent'); request.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');");
|
|
220
|
+
* @see https://github.com/lightbody/browsermob-proxy#rest-api-interceptors-with-littleproxy
|
|
221
|
+
*/
|
|
222
|
+
async setRequestInterceptor(port, interceptor) {
|
|
223
|
+
await this.httpRequest({
|
|
224
|
+
path: `/proxy/${port}/filter/request`,
|
|
225
|
+
method: Method.POST,
|
|
226
|
+
headers: {
|
|
227
|
+
'Content-Type': 'text/plain',
|
|
228
|
+
},
|
|
229
|
+
}, interceptor);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Set response interceptor
|
|
233
|
+
* example: await proxy.setResponseInterceptor(port, "response.headers().remove('User-Agent'); response.headers().add('User-Agent', 'My-Custom-User-Agent-String 1.0');");
|
|
234
|
+
* @see https://github.com/lightbody/browsermob-proxy#rest-api-interceptors-with-littleproxy
|
|
235
|
+
*/
|
|
236
|
+
async setResponseInterceptor(port, interceptor) {
|
|
237
|
+
await this.httpRequest({
|
|
238
|
+
path: `/proxy/${port}/filter/response`,
|
|
239
|
+
method: Method.POST,
|
|
240
|
+
headers: {
|
|
241
|
+
'Content-Type': 'text/plain',
|
|
242
|
+
},
|
|
243
|
+
}, interceptor);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
102
246
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAwB,MAAM,MAAM,CAAC;AAkB5C,IAAK,MAKJ;AALD,WAAK,MAAM;IACT,qBAAW,CAAA;IACX,uBAAa,CAAA;IACb,qBAAW,CAAA;IACX,2BAAiB,CAAA;AACnB,CAAC,EALI,MAAM,KAAN,MAAM,QAKV;AAED,MAAM,CAAC,OAAO,OAAO,wBAAwB;IA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version": "0.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git@github.com:raul72/browsermob-proxy-api-client.git"
|
|
15
15
|
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@types/har-format": "^1.2.10"
|
|
18
|
+
},
|
|
16
19
|
"devDependencies": {
|
|
17
20
|
"@microsoft/eslint-formatter-sarif": "2.1.7",
|
|
18
21
|
"@types/node": "^16",
|