proxy
Provides methods for intercepting network traffic via mitmproxy.

assertStatusCode

Assert whether HTTP response status code matches the specified value.
Parameters:
Name
Type
Description
url
String|RegExp
A request URL to match verbatim or a RegExp.
statusCode
Number
A response status code to match verbatim or a RegExp.
failureMessage
String
optional An optional failure message.
timeout
Number
optional Timeout. Default is 60 seconds.
Returns:
Object - Network request details if the network request was found.

assertUrl

Assert if network request matching the specified URL.
Parameters:
Name
Type
Description
url
String|RegExp
A request URL to match verbatim or a RegExp.
timeout
Number
optional Timeout. Default is 60 seconds.
Returns:
Object - Network request details if the network request was found.

dispose

Disposes this module.

getRequests

Return all the collected network requests so far.
Returns:
Array.<Object> - Array containing network requests.

init

Initializes proxy.
Launching mitmproxy manually:
1
mitmdump --anticache -s mitmproxy-node\scripts\proxy.py --ssl-insecure --set httpCommPort=8765
Copied!
Parameters:
Name
Type
Description
proxyPort
Number
Proxy port.
proxyCommPort
Number
optional Port for internal proxy communication. If specified, then mitmproxy should be launched manually.Otherwise mitmpoxy will be launched automatically.
saveRequestBody
Boolean
optional Save request bodies.
saveResponseBody
Boolean
optional Save response bodies.

start

Begin collecting network requests.
Any previously collected requests will be discarded.
Usage example:
1
proxy.init(8080);
2
proxy.start();
3
// print the collected request so far:
4
let requests = proxy.getRequests();
5
for (let req of requests) {
6
log.info(req);
7
}
8
// wait for a request using a verbatim URL match:
9
proxy.waitForUrl('https://www.yourwebsite.com/foo/bar');
10
// wait for a request using a regular expression URL match:
11
proxy.waitForUrl(/https:\/\/.*\/foo\/bar/);
12
// wait for a request using a custom matcher:
13
proxy.waitFor(function (request) {
14
return request.status === '200' && request.url === 'https://www.yourwebsite.com/foo/bar';
15
});
Copied!

stop

Stop collecting network requests.

waitFor

Wait for a network request.
Parameters:
Name
Type
Description
matcher
Function
Matching function. Should return true on match, or false otherwise.
timeout
Number
optional Timeout. Default is 60 seconds.
Returns:
Object - Network request details if the network request was found.

waitForUrl

Wait for a network request matching the specified URL.
Parameters:
Name
Type
Description
pattern
String|RegExp
An URL to match verbatim or a RegExp.
timeout
Number
optional Timeout. Default is 60 seconds.
Returns:
Object - Network request details if the network request was found.
Last modified 24d ago