Releases: httptoolkit/mockttp
Releases · httptoolkit/mockttp
v3.0.0
💥 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.
v2.0.0
💥 Breaking changes:
- Some unusual content encodings (notably Brotli) are no longer handled automatically when using the (now deprecated) synchronous properties. If you're using
body.decodedBuffer
,body.text
,body.json
orbody.formData
you should switch to the correspondingbody.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. - Node v10 is no longer officially supported as it's now EOL. It still works right now, but it's no longer tested, and it's likely to stop working without warning in future versions.
Other big changes:
- For common cases, you can now automatically transform proxied content using
transformRequest
andtransformResponse
options, instead of providing your own custombeforeRequest
andbeforeResponse
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. ThebeforeX
options still exist and are fully supported, but they're recommended only for advanced use cases. - Chaining mockttp with upstream proxies is now supported, using the
proxyConfig
option with passthrough rules.