% title = 'proxies' description = 'Using mountebank to record and playback through proxying to a real network dependency' %> <%- include('../../_header') -%>
Proxies are one of the most powerful features of mountebank, rivaled only by the
mighty injection. Proxies support record/replay
behavior to easily capture a rich set of test data for your test scenarios.
Each proxy definition allows you to define the fields which should be included
in newly created predicates
.
proxy
response types take the following parameters:
Parameter | Default | Type | Description |
---|---|---|---|
to |
required | A URL without the path (e.g. http://someserver:3000 or tcp://someserver:3000) | Defines the origin server that the request should proxy to. |
predicateGenerators |
[] |
array | An array of objects that defines how the predicates for new stubs are created. Each object in the array defines the fields to generate predicates from. See below for examples. |
mode |
proxyOnce |
string, one of proxyOnce , proxyAlways or proxyTransparent . |
Defines the replay behavior of the proxy. The default proxyOnce mode
doesn't require you to explicitly do anything to replay the proxied responses. The
proxyAlways mode requires you to run the
mb replay command (or equivalent) to
switch from record mode to replay mode, but allows a richer set of data to be
recorded. The proxyTransparent mode proxies the request but does not record any data.
See below for details. |
addWaitBehavior |
false |
boolean | If true, mountebank will add a wait
behavior to the response with the same latency that the proxied call took. This is useful in performance
testing scenarios where you want to simulate the actual latency of downstream services that you're
virtualizing. |
addDecorateBehavior |
null |
string, JavaScript | If defined, mountebank will add a decorate
behavior to the saved response. |
http and https proxies add additional optional parameters:
Parameter | Default | Type | Description |
---|---|---|---|
cert |
null |
A PEM-formatted string | The SSL client certificate |
key |
null |
A PEM-formatted string | The SSL client private key |
ciphers |
Here | A valid cipher (see this page for formats) | For older (and insecure) https servers, this field allows you to override the cipher used to communicate |
secureProtocol |
TLS_method |
A valid OpenSSL protocol method name | The SSL method to use |
passphrase |
null |
string | Shared passphrase used for a single private key |
injectHeaders |
{} |
object | Key-value pairs of headers to inject into the proxied request. |
tcp proxies support the following optional configuration:
Parameter | Default | Type | Description |
---|---|---|---|
keepalive |
false |
boolean | If true, mountebank will not close the connection on each proxied request |
It is occasionally useful to capture how long the original proxied request takes. mountebank
stores the number of milliseconds for the request in the _proxyResponseTime
field in the
response. Setting the addWaitBehavior
flag will add that latency to the saved response.
Select the behavior of the proxy below for a relevant example: