Powerful friendly HTTP mock server & proxy library
:boom: Breaking changes:
.for[...]()
, such as mockServer.get()
, mockServer.post()
and mockServer.anyRequest()
were removed. These were previously deprecated in v2.5.0. These can all be replaced with the equivalent forX
method, e.g. mockServer.forGet()
, mockServer.forPost()
and mockServer.forAnyRequest()
. All rule builder methods now consistently start with mockServer.forX()
.Mockttp.getStandalone()
is now Mockttp.getAdminServer()
.activeServerPorts
method has been removed, and the mock-server-started/stopping
events have been replaced with mock-session-started/stopping
.handlers
and MockRuleData
root exports have been removed, they should be replaced with requestHandlers
and RequestRuleData
.tlsClientError
mockttp instance subscription event has been removed, it should be replaced with tls-client-error
instead.ignoreHostCertificateErrors
passthrough rule option was removed, it should be replaced with the new ignoreHostHttpsErrors
instead.addRules
and setRules
methods have been removed, they should be replaced with addRequestRules
and setRequestRules
.setFallbackRule
method has been removed, it should be replaced by setting rules with the new priority: 0
field instead.thenJSON
request rule builder method has been removed, it should be replaced with thenJson
instead.body.decodedBuffer
, body.text
, body.json
and body.formData
. They should be replaced with the body.getDecodedBuffer()
, .getText()
, .getJson()
and .getFormData()
asynchronous methods instead.body
or json
field from a callback (thenCallback
, beforeRequest
or beforeResponse
), the request or response body will now be automatically encoded to match its content-encoding
header. Previously transformRequest/Response
results were automatically encoded but nothing else. To return raw data that should not be encoded automatically, return rawBody
instead with a Buffer/Uint8Array, and that will be used as-is with no encoding applied.header
object (lowercased header string keys to single-string or array-of-string values) and a rawHeader
array (an array of [string name, string value] pairs, with the exact order & casing that they were received).transformRequest/Response
object or beforeRequest/Response
callback. In that case, the headers will be normalized before forwarding, lowercasing header names and potentially changing header order..on(event)
subscriptions are now reset when a Mockttp instance resets, either due to mockServer.reset()
or .stop()
and .start()
(previously only rules were reset).mockServer.forAnyWebSocket().thenPassThrough()
.Other.changes:
forUnmatchedRequest()
, added support for using matchers on fallback rules, and added asPriority(n)
to define multiple custom layers of multiple rules at different priorities.thenRejectConnection
to reject websocket connections with a given HTTP response.body.decodedBuffer
, body.text
, body.json
or body.formData
you should switch to the corresponding body.getX()
methods instead. These methods decode content asynchronously, improving performance especially with parallel requests, and they support more encodings (including Brotli and Zstandard).
Gzip, deflate, and unencoded content all still work both sync or async, so nothing will break in these common cases, but moving to the async functions is recommended regardless.transformRequest
and transformResponse
options, instead of providing your own custom beforeRequest
and beforeResponse
callbacks. These support completely replacing and/or updating most properties of proxied content, they make your code simpler, and in many cases they're significantly faster. The beforeX
options still exist and are fully supported, but they're recommended only for advanced use cases.proxyConfig
option with passthrough rules.