💥 Breaking changes:
- Mockttp no longer supports Node.js v12, which is now end-of-life. The new minimum version is Node v14.14.0.
- Lots of previously deprecated APIs were removed:
- All rule definition that didn't start with
.for[...]()
, such asmockServer.get()
,mockServer.post()
andmockServer.anyRequest()
were removed. These were previously deprecated in v2.5.0. These can all be replaced with the equivalentforX
method, e.g.mockServer.forGet()
,mockServer.forPost()
andmockServer.forAnyRequest()
. All rule builder methods now consistently start withmockServer.forX()
. - Standalone servers are now admin servers, and all previously-deprecated references to 'standalone' have been replaced with 'admin', for example
Mockttp.getStandalone()
is nowMockttp.getAdminServer()
. - The admin server's (previously the standalone server's)
activeServerPorts
method has been removed, and themock-server-started/stopping
events have been replaced withmock-session-started/stopping
. - The deprecated
handlers
andMockRuleData
root exports have been removed, they should be replaced withrequestHandlers
andRequestRuleData
. - The deprecated
tlsClientError
mockttp instance subscription event has been removed, it should be replaced withtls-client-error
instead. - The deprecated
ignoreHostCertificateErrors
passthrough rule option was removed, it should be replaced with the newignoreHostHttpsErrors
instead. - The previously deprecated
addRules
andsetRules
methods have been removed, they should be replaced withaddRequestRules
andsetRequestRules
. - The
setFallbackRule
method has been removed, it should be replaced by setting rules with the newpriority: 0
field instead. - The deprecated
thenJSON
request rule builder method has been removed, it should be replaced withthenJson
instead. - The deprecated synchronous body decoding methods have been removed:
body.decodedBuffer
,body.text
,body.json
andbody.formData
. They should be replaced with thebody.getDecodedBuffer()
,.getText()
,.getJson()
and.getFormData()
asynchronous methods instead. - The body property on aborted request event data has been removed (previously it was present but always empty).
- All rule definition that didn't start with
- When returning a result with a
body
orjson
field from a callback (thenCallback
,beforeRequest
orbeforeResponse
), the request or response body will now be automatically encoded to match itscontent-encoding
header. PreviouslytransformRequest/Response
results were automatically encoded but nothing else. To return raw data that should not be encoded automatically, returnrawBody
instead with a Buffer/Uint8Array, and that will be used as-is with no encoding applied. - Mockttp is now considerably stricter about preserving raw header data (i.e. header order, duplicate headers and heading name casing) when reporting and proxying requests. Officially this is not semantically meaningful in HTTP, and should not affect any correct server/client implementations, but in practice some tools may behave differently. For Mockttp users, this means:
- All exposed requests & responses now include both a
header
object (lowercased header string keys to single-string or array-of-string values) and arawHeader
array (an array of [string name, string value] pairs, with the exact order & casing that they were received). - When using passthrough rules, proxied traffic preserves the exact header formatting for upstream requests and returned responses where possible. The one case when this isn't possible is when setting headers with a
transformRequest/Response
object orbeforeRequest/Response
callback. In that case, the headers will be normalized before forwarding, lowercasing header names and potentially changing header order.
- All exposed requests & responses now include both a
- All
.on(event)
subscriptions are now reset when a Mockttp instance resets, either due tomockServer.reset()
or.stop()
and.start()
(previously only rules were reset). - Incoming websockets that don't match any rule are now rejected with a 503 (previously they were automatically proxied by default). This matches the behaviour for unmatched HTTP requests. To continue proxying websocket traffic, define an explicit rule like
mockServer.forAnyWebSocket().thenPassThrough()
.
Other.changes:
- Added forPort and forHostname matchers, for more precise host matching (in addition to forHost, which matches the host header including some implicit header behaviour)
- Added support for multiple fallback rules with
forUnmatchedRequest()
, added support for using matchers on fallback rules, and addedasPriority(n)
to define multiple custom layers of multiple rules at different priorities. - Added
thenRejectConnection
to reject websocket connections with a given HTTP response.