diff --git a/docs/README.md b/docs/README.md
index c7d170e..5dd0d0f 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -16,6 +16,7 @@
* ["http-serializer"](modules/_http_serializer_.md)
* ["index"](modules/_index_.md)
* ["interceptor"](modules/_interceptor_.md)
+* ["mock-response"](modules/_mock_response_.md)
* ["recording"](modules/_recording_.md)
* ["yesno"](modules/_yesno_.md)
diff --git a/docs/classes/_context_.context.md b/docs/classes/_context_.context.md
index 4e1b749..92f4e63 100644
--- a/docs/classes/_context_.context.md
+++ b/docs/classes/_context_.context.md
@@ -12,18 +12,33 @@ Store the current execution context for YesNo by tracking requests & mocks.
### Properties
+* [comparatorFn](_context_.context.md#comparatorfn)
* [inFlightRequests](_context_.context.md#inflightrequests)
* [interceptedRequestsCompleted](_context_.context.md#interceptedrequestscompleted)
* [loadedMocks](_context_.context.md#loadedmocks)
+* [mode](_context_.context.md#mode)
+* [responsesForMatchingRequests](_context_.context.md#responsesformatchingrequests)
### Methods
+* [addResponseForMatchingRequests](_context_.context.md#addresponseformatchingrequests)
* [clear](_context_.context.md#clear)
+* [getMatchingIntercepted](_context_.context.md#getmatchingintercepted)
+* [getMatchingMocks](_context_.context.md#getmatchingmocks)
+* [getResponseDefinedMatching](_context_.context.md#getresponsedefinedmatching)
+* [hasResponsesDefinedForMatchers](_context_.context.md#hasresponsesdefinedformatchers)
---
## Properties
+
+
+### comparatorFn
+
+**● comparatorFn**: *[ComparatorFn](../modules/_filtering_comparator_.md#comparatorfn)* = comparatorByUrl
+
+___
### inFlightRequests
@@ -50,10 +65,39 @@ ___
Serialized records loaded from disk.
+___
+
+
+### mode
+
+**● mode**: *`Mode`* = Mode.Spy
+
+___
+
+
+### responsesForMatchingRequests
+
+**● responsesForMatchingRequests**: *[IResponseForMatchingRequest](../interfaces/_context_.iresponseformatchingrequest.md)[]* = []
+
___
## Methods
+
+
+### addResponseForMatchingRequests
+
+▸ **addResponseForMatchingRequests**(matchingResponse: *[IResponseForMatchingRequest](../interfaces/_context_.iresponseformatchingrequest.md)*): `void`
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| matchingResponse | [IResponseForMatchingRequest](../interfaces/_context_.iresponseformatchingrequest.md) |
+
+**Returns:** `void`
+
+___
### clear
@@ -63,4 +107,58 @@ ___
**Returns:** `void`
___
+
+
+### getMatchingIntercepted
+
+▸ **getMatchingIntercepted**(matcher: *[Matcher](../modules/_filtering_matcher_.md#matcher)*): [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| matcher | [Matcher](../modules/_filtering_matcher_.md#matcher) |
+
+**Returns:** [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+___
+
+
+### getMatchingMocks
+
+▸ **getMatchingMocks**(matcher: *[Matcher](../modules/_filtering_matcher_.md#matcher)*): [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| matcher | [Matcher](../modules/_filtering_matcher_.md#matcher) |
+
+**Returns:** [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+___
+
+
+### getResponseDefinedMatching
+
+▸ **getResponseDefinedMatching**(request: *[ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md)*): [ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md) | `undefined`
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| request | [ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md) |
+
+**Returns:** [ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md) | `undefined`
+
+___
+
+
+### hasResponsesDefinedForMatchers
+
+▸ **hasResponsesDefinedForMatchers**(): `boolean`
+
+**Returns:** `boolean`
+
+___
diff --git a/docs/classes/_filtering_collection_.filteredhttpcollection.md b/docs/classes/_filtering_collection_.filteredhttpcollection.md
index 079b6f6..5ac9ab6 100644
--- a/docs/classes/_filtering_collection_.filteredhttpcollection.md
+++ b/docs/classes/_filtering_collection_.filteredhttpcollection.md
@@ -32,6 +32,7 @@ Can filter both intercepted HTTP requests and loaded mocks.
* [only](_filtering_collection_.filteredhttpcollection.md#only)
* [redact](_filtering_collection_.filteredhttpcollection.md#redact)
* [request](_filtering_collection_.filteredhttpcollection.md#request)
+* [respond](_filtering_collection_.filteredhttpcollection.md#respond)
* [response](_filtering_collection_.filteredhttpcollection.md#response)
---
@@ -142,6 +143,27 @@ Throws an exception if multiple requests were matched.
**Returns:** [ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md)
+___
+
+
+### respond
+
+▸ **respond**(response: *[PartialResponseForRequest](../modules/_filtering_collection_.md#partialresponseforrequest)*): `void`
+
+Provide a mock response for all matching requests.
+
+Use callback to dynamically generate response per request.
+
+Matching responses defined here take _precedence_ over mocks loaded normally.
+
+**Parameters:**
+
+| Name | Type | Description |
+| ------ | ------ | ------ |
+| response | [PartialResponseForRequest](../modules/_filtering_collection_.md#partialresponseforrequest) | Serialized HTTP response or callback |
+
+**Returns:** `void`
+
___
diff --git a/docs/classes/_interceptor_.interceptor.md b/docs/classes/_interceptor_.interceptor.md
index 518233b..0552254 100644
--- a/docs/classes/_interceptor_.interceptor.md
+++ b/docs/classes/_interceptor_.interceptor.md
@@ -18,19 +18,13 @@ Uses MITM library to spy on HTTP requests made in current NodeJS process.
## Index
-### Constructors
-
-* [constructor](_interceptor_.interceptor.md#constructor)
-
### Properties
* [clientRequests](_interceptor_.interceptor.md#clientrequests)
-* [comparatorFn](_interceptor_.interceptor.md#comparatorfn)
* [ignorePorts](_interceptor_.interceptor.md#ignoreports)
* [mitm](_interceptor_.interceptor.md#mitm)
* [origOnSocket](_interceptor_.interceptor.md#origonsocket)
* [requestNumber](_interceptor_.interceptor.md#requestnumber)
-* [shouldProxy](_interceptor_.interceptor.md#shouldproxy)
* [defaultMaxListeners](_interceptor_.interceptor.md#defaultmaxlisteners)
### Methods
@@ -51,7 +45,6 @@ Uses MITM library to spy on HTTP requests made in current NodeJS process.
* [once](_interceptor_.interceptor.md#once)
* [prependListener](_interceptor_.interceptor.md#prependlistener)
* [prependOnceListener](_interceptor_.interceptor.md#prependoncelistener)
-* [proxy](_interceptor_.interceptor.md#proxy)
* [rawListeners](_interceptor_.interceptor.md#rawlisteners)
* [removeAllListeners](_interceptor_.interceptor.md#removealllisteners)
* [removeListener](_interceptor_.interceptor.md#removelistener)
@@ -61,24 +54,6 @@ Uses MITM library to spy on HTTP requests made in current NodeJS process.
---
-## Constructors
-
-
-
-### constructor
-
-⊕ **new Interceptor**(options?: * `undefined` | `object`*): [Interceptor](_interceptor_.interceptor.md)
-
-**Parameters:**
-
-| Name | Type |
-| ------ | ------ |
-| `Optional` options | `undefined` | `object`|
-
-**Returns:** [Interceptor](_interceptor_.interceptor.md)
-
-___
-
## Properties
@@ -87,13 +62,6 @@ ___
**● clientRequests**: *[ClientRequestTracker](../interfaces/_interceptor_.clientrequesttracker.md)*
-___
-
-
-### ```` comparatorFn
-
-**● comparatorFn**: *[ComparatorFn](../modules/_filtering_comparator_.md#comparatorfn)*
-
___
@@ -123,13 +91,6 @@ ___
**● requestNumber**: *`number`* = 0
-___
-
-
-### `` shouldProxy
-
-**● shouldProxy**: *`boolean`* = true
-
___
@@ -384,23 +345,6 @@ ___
**Returns:** `this`
-___
-
-
-### proxy
-
-▸ **proxy**(shouldProxy: *`boolean`*): `void`
-
-Enable/disable proxying. If proxying, requests are not sent to their original destination.
-
-**Parameters:**
-
-| Name | Type | Description |
-| ------ | ------ | ------ |
-| shouldProxy | `boolean` | Whether or not to proxy |
-
-**Returns:** `void`
-
___
diff --git a/docs/classes/_mock_response_.mockresponse.md b/docs/classes/_mock_response_.mockresponse.md
new file mode 100644
index 0000000..7ee0cf0
--- /dev/null
+++ b/docs/classes/_mock_response_.mockresponse.md
@@ -0,0 +1,128 @@
+[yesno-http](../README.md) > ["mock-response"](../modules/_mock_response_.md) > [MockResponse](../classes/_mock_response_.mockresponse.md)
+
+# Class: MockResponse
+
+## Hierarchy
+
+**MockResponse**
+
+## Index
+
+### Constructors
+
+* [constructor](_mock_response_.mockresponse.md#constructor)
+
+### Properties
+
+* [ctx](_mock_response_.mockresponse.md#ctx)
+* [event](_mock_response_.mockresponse.md#event)
+
+### Methods
+
+* [assertMockMatches](_mock_response_.mockresponse.md#assertmockmatches)
+* [getMockForIntecept](_mock_response_.mockresponse.md#getmockforintecept)
+* [send](_mock_response_.mockresponse.md#send)
+* [writeMockResponse](_mock_response_.mockresponse.md#writemockresponse)
+
+---
+
+## Constructors
+
+
+
+### constructor
+
+⊕ **new MockResponse**(event: *[IInterceptEvent](../interfaces/_interceptor_.iinterceptevent.md)*, ctx: *[Context](_context_.context.md)*): [MockResponse](_mock_response_.mockresponse.md)
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| event | [IInterceptEvent](../interfaces/_interceptor_.iinterceptevent.md) |
+| ctx | [Context](_context_.context.md) |
+
+**Returns:** [MockResponse](_mock_response_.mockresponse.md)
+
+___
+
+## Properties
+
+
+
+### `` ctx
+
+**● ctx**: *[Context](_context_.context.md)*
+
+___
+
+
+### `` event
+
+**● event**: *[IInterceptEvent](../interfaces/_interceptor_.iinterceptevent.md)*
+
+___
+
+## Methods
+
+
+
+### `` assertMockMatches
+
+▸ **assertMockMatches**(__namedParameters: *`object`*): `void`
+
+**Parameters:**
+
+**__namedParameters: `object`**
+
+| Name | Type |
+| ------ | ------ |
+| mock | [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md) |
+| requestNumber | `number` |
+| serializedRequest | [ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md) |
+
+**Returns:** `void`
+
+___
+
+
+### `` getMockForIntecept
+
+▸ **getMockForIntecept**(__namedParameters: *`object`*): [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)
+
+**Parameters:**
+
+**__namedParameters: `object`**
+
+| Name | Type |
+| ------ | ------ |
+| requestNumber | `number` |
+
+**Returns:** [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)
+
+___
+
+
+### send
+
+▸ **send**(): `Promise`< [ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md) | `undefined`>
+
+**Returns:** `Promise`< [ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md) | `undefined`>
+
+___
+
+
+### `` writeMockResponse
+
+▸ **writeMockResponse**(response: *[ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md)*, interceptedResponse: *`ServerResponse`*): `void`
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| response | [ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md) |
+| interceptedResponse | `ServerResponse` |
+
+**Returns:** `void`
+
+___
+
diff --git a/docs/classes/_yesno_.yesno.md b/docs/classes/_yesno_.yesno.md
index 9beb9eb..0b9aeea 100644
--- a/docs/classes/_yesno_.yesno.md
+++ b/docs/classes/_yesno_.yesno.md
@@ -22,7 +22,6 @@ Client API for YesNo
* [ctx](_yesno_.yesno.md#ctx)
* [interceptor](_yesno_.yesno.md#interceptor)
-* [mode](_yesno_.yesno.md#mode)
### Methods
@@ -37,9 +36,11 @@ Client API for YesNo
* [load](_yesno_.yesno.md#load)
* [matching](_yesno_.yesno.md#matching)
* [mock](_yesno_.yesno.md#mock)
-* [mockResponse](_yesno_.yesno.md#mockresponse)
* [mocks](_yesno_.yesno.md#mocks)
-* [recordCompleted](_yesno_.yesno.md#recordcompleted)
+* [onIntercept](_yesno_.yesno.md#onintercept)
+* [onProxied](_yesno_.yesno.md#onproxied)
+* [recordRequest](_yesno_.yesno.md#recordrequest)
+* [recordResponse](_yesno_.yesno.md#recordresponse)
* [recording](_yesno_.yesno.md#recording)
* [redact](_yesno_.yesno.md#redact)
* [restore](_yesno_.yesno.md#restore)
@@ -84,13 +85,6 @@ ___
**● interceptor**: *[Interceptor](_interceptor_.interceptor.md)*
-___
-
-
-### `` mode
-
-**● mode**: *`Mode`* = Mode.Spy
-
___
## Methods
@@ -121,7 +115,7 @@ ___
### `` enable
-▸ **enable**(options?: *[IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md)*): [YesNo](_yesno_.yesno.md)
+▸ **enable**(options?: *[IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md)*): [YesNo](_yesno_.yesno.md)
Enable intercepting requests
@@ -129,7 +123,7 @@ Enable intercepting requests
| Name | Type |
| ------ | ------ |
-| `Optional` options | [IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md) |
+| `Optional` options | [IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md) |
**Returns:** [YesNo](_yesno_.yesno.md)
@@ -234,7 +228,7 @@ ___
### mock
-▸ **mock**(mocks: *[IHttpMock](../interfaces/_file_.ihttpmock.md)[]*, options?: *[IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md)*): `void`
+▸ **mock**(mocks: *[IHttpMock](../interfaces/_file_.ihttpmock.md)[]*, options?: *[IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md)*): `void`
Mock responses for intercepted requests
*__todo__*: Reset the request counter?
@@ -244,16 +238,42 @@ Mock responses for intercepted requests
| Name | Type |
| ------ | ------ |
| mocks | [IHttpMock](../interfaces/_file_.ihttpmock.md)[] |
-| `Optional` options | [IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md) |
+| `Optional` options | [IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md) |
**Returns:** `void`
___
-
+
+
+### mocks
+
+▸ **mocks**(): [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+Get all loaded mocks
+
+**Returns:** [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+
+___
+
+
+### `` onIntercept
+
+▸ **onIntercept**(event: *[IInterceptEvent](../interfaces/_interceptor_.iinterceptevent.md)*): `Promise`<`void`>
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| event | [IInterceptEvent](../interfaces/_interceptor_.iinterceptevent.md) |
+
+**Returns:** `Promise`<`void`>
+
+___
+
-### `` mockResponse
+### `` onProxied
-▸ **mockResponse**(__namedParameters: *`object`*): `Promise`<`void`>
+▸ **onProxied**(__namedParameters: *`object`*): `void`
**Parameters:**
@@ -261,32 +281,34 @@ ___
| Name | Type |
| ------ | ------ |
-| clientRequest | `ClientRequest` |
-| comparatorFn | `undefined` | `function`|
-| interceptedRequest | `IncomingMessage` |
-| interceptedResponse | `ServerResponse` |
| requestNumber | `number` |
| requestSerializer | [RequestSerializer](_http_serializer_.requestserializer.md) |
+| responseSerializer | [ResponseSerializer](_http_serializer_.responseserializer.md) |
-**Returns:** `Promise`<`void`>
+**Returns:** `void`
___
-
+
-### mocks
+### `` recordRequest
-▸ **mocks**(): [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+▸ **recordRequest**(requestSerializer: *[RequestSerializer](_http_serializer_.requestserializer.md)*, requestNumber: *`number`*): `void`
-Get all loaded mocks
+**Parameters:**
-**Returns:** [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)[]
+| Name | Type |
+| ------ | ------ |
+| requestSerializer | [RequestSerializer](_http_serializer_.requestserializer.md) |
+| requestNumber | `number` |
+
+**Returns:** `void`
___
-
+
-### `` recordCompleted
+### `` recordResponse
-▸ **recordCompleted**(request: *[ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md)*, response: *[ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md)*, requestNumber: *`number`*): `void`
+▸ **recordResponse**(request: *[ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md)*, response: *[ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md)*, requestNumber: *`number`*): `void`
**Parameters:**
@@ -402,7 +424,7 @@ ___
### spy
-▸ **spy**(options?: *[IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md)*): `void`
+▸ **spy**(options?: *[IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md)*): `void`
Spy on intercepted requests
@@ -410,7 +432,7 @@ Spy on intercepted requests
| Name | Type |
| ------ | ------ |
-| `Optional` options | [IInterceptOptions](../interfaces/_interceptor_.iinterceptoptions.md) |
+| `Optional` options | [IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md) |
**Returns:** `void`
diff --git a/docs/interfaces/_context_.iresponseformatchingrequest.md b/docs/interfaces/_context_.iresponseformatchingrequest.md
new file mode 100644
index 0000000..6d8e360
--- /dev/null
+++ b/docs/interfaces/_context_.iresponseformatchingrequest.md
@@ -0,0 +1,34 @@
+[yesno-http](../README.md) > ["context"](../modules/_context_.md) > [IResponseForMatchingRequest](../interfaces/_context_.iresponseformatchingrequest.md)
+
+# Interface: IResponseForMatchingRequest
+
+## Hierarchy
+
+**IResponseForMatchingRequest**
+
+## Index
+
+### Properties
+
+* [matcher](_context_.iresponseformatchingrequest.md#matcher)
+* [response](_context_.iresponseformatchingrequest.md#response)
+
+---
+
+## Properties
+
+
+
+### matcher
+
+**● matcher**: *[Matcher](../modules/_filtering_matcher_.md#matcher)*
+
+___
+
+
+### response
+
+**● response**: *[PartialResponseForRequest](../modules/_filtering_collection_.md#partialresponseforrequest)*
+
+___
+
diff --git a/docs/interfaces/_filtering_collection_.ifilteredhttpcollectionparams.md b/docs/interfaces/_filtering_collection_.ifilteredhttpcollectionparams.md
index e5e7e0d..b3af858 100644
--- a/docs/interfaces/_filtering_collection_.ifilteredhttpcollectionparams.md
+++ b/docs/interfaces/_filtering_collection_.ifilteredhttpcollectionparams.md
@@ -28,8 +28,7 @@ ___
### `` matcher
-**● matcher**: * [ISerializedHttpPartialDeepMatch](_filtering_matcher_.iserializedhttppartialdeepmatch.md) | [MatchFn](../modules/_filtering_matcher_.md#matchfn)
-*
+**● matcher**: *[Matcher](../modules/_filtering_matcher_.md#matcher)*
___
diff --git a/docs/interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md b/docs/interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md
new file mode 100644
index 0000000..d3aa276
--- /dev/null
+++ b/docs/interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md
@@ -0,0 +1,34 @@
+[yesno-http](../README.md) > ["filtering/matcher"](../modules/_filtering_matcher_.md) > [ISeralizedRequestResponseToMatch](../interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md)
+
+# Interface: ISeralizedRequestResponseToMatch
+
+## Hierarchy
+
+**ISeralizedRequestResponseToMatch**
+
+## Index
+
+### Properties
+
+* [request](_filtering_matcher_.iseralizedrequestresponsetomatch.md#request)
+* [response](_filtering_matcher_.iseralizedrequestresponsetomatch.md#response)
+
+---
+
+## Properties
+
+
+
+### request
+
+**● request**: *[ISerializedRequest](_http_serializer_.iserializedrequest.md)*
+
+___
+
+
+### `` response
+
+**● response**: *[ISerializedResponse](_http_serializer_.iserializedresponse.md)*
+
+___
+
diff --git a/docs/interfaces/_http_serializer_.iseralizedrequestresponse.md b/docs/interfaces/_http_serializer_.iseralizedrequestresponse.md
new file mode 100644
index 0000000..538985b
--- /dev/null
+++ b/docs/interfaces/_http_serializer_.iseralizedrequestresponse.md
@@ -0,0 +1,36 @@
+[yesno-http](../README.md) > ["http-serializer"](../modules/_http_serializer_.md) > [ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md)
+
+# Interface: ISeralizedRequestResponse
+
+HTTP request & response
+
+## Hierarchy
+
+**ISeralizedRequestResponse**
+
+## Index
+
+### Properties
+
+* [request](_http_serializer_.iseralizedrequestresponse.md#request)
+* [response](_http_serializer_.iseralizedrequestresponse.md#response)
+
+---
+
+## Properties
+
+
+
+### request
+
+**● request**: *[ISerializedRequest](_http_serializer_.iserializedrequest.md)*
+
+___
+
+
+### response
+
+**● response**: *[ISerializedResponse](_http_serializer_.iserializedresponse.md)*
+
+___
+
diff --git a/docs/interfaces/_http_serializer_.iserializedhttp.md b/docs/interfaces/_http_serializer_.iserializedhttp.md
index a4419c4..a9806d0 100644
--- a/docs/interfaces/_http_serializer_.iserializedhttp.md
+++ b/docs/interfaces/_http_serializer_.iserializedhttp.md
@@ -2,7 +2,7 @@
# Interface: ISerializedHttp
-HTTP request/response serialized in a consistent format to be stored on disk in a mocks file
+HTTP request/response serialized in a consistent format
## Hierarchy
diff --git a/docs/interfaces/_interceptor_.iinterceptevent.md b/docs/interfaces/_interceptor_.iinterceptevent.md
index 051cb24..8bcae42 100644
--- a/docs/interfaces/_interceptor_.iinterceptevent.md
+++ b/docs/interfaces/_interceptor_.iinterceptevent.md
@@ -2,6 +2,8 @@
# Interface: IInterceptEvent
+Event emitted whenever we intercept an HTTP request
+
## Hierarchy
**IInterceptEvent**
@@ -11,9 +13,9 @@
### Properties
* [clientRequest](_interceptor_.iinterceptevent.md#clientrequest)
-* [comparatorFn](_interceptor_.iinterceptevent.md#comparatorfn)
* [interceptedRequest](_interceptor_.iinterceptevent.md#interceptedrequest)
* [interceptedResponse](_interceptor_.iinterceptevent.md#interceptedresponse)
+* [proxy](_interceptor_.iinterceptevent.md#proxy)
* [requestNumber](_interceptor_.iinterceptevent.md#requestnumber)
* [requestSerializer](_interceptor_.iinterceptevent.md#requestserializer)
@@ -27,12 +29,7 @@
**● clientRequest**: *`ClientRequest`*
-___
-
-
-### `` comparatorFn
-
-**● comparatorFn**: *[ComparatorFn](../modules/_filtering_comparator_.md#comparatorfn)*
+The client request which initiated the HTTP request
___
@@ -41,6 +38,8 @@ ___
**● interceptedRequest**: *`IncomingMessage`*
+Request arriving to our MITM proxy
+
___
@@ -48,6 +47,22 @@ ___
**● interceptedResponse**: *`ServerResponse`*
+Response from our MITM proxy
+
+___
+
+
+### proxy
+
+**● proxy**: *`function`*
+
+Proxy the intercepted request to its original destination
+
+#### Type declaration
+▸(): `void`
+
+**Returns:** `void`
+
___
diff --git a/docs/interfaces/_interceptor_.iinterceptoptions.md b/docs/interfaces/_interceptor_.iinterceptoptions.md
index 2de5299..cc991a4 100644
--- a/docs/interfaces/_interceptor_.iinterceptoptions.md
+++ b/docs/interfaces/_interceptor_.iinterceptoptions.md
@@ -6,24 +6,18 @@
**IInterceptOptions**
+↳ [IYesNoInterceptingOptions](_yesno_.iyesnointerceptingoptions.md)
+
## Index
### Properties
-* [comparatorFn](_interceptor_.iinterceptoptions.md#comparatorfn)
* [ignorePorts](_interceptor_.iinterceptoptions.md#ignoreports)
---
## Properties
-
-
-### `` comparatorFn
-
-**● comparatorFn**: *[ComparatorFn](../modules/_filtering_comparator_.md#comparatorfn)*
-
-___
### `` ignorePorts
diff --git a/docs/interfaces/_yesno_.iyesnointerceptingoptions.md b/docs/interfaces/_yesno_.iyesnointerceptingoptions.md
new file mode 100644
index 0000000..60ab1c3
--- /dev/null
+++ b/docs/interfaces/_yesno_.iyesnointerceptingoptions.md
@@ -0,0 +1,36 @@
+[yesno-http](../README.md) > ["yesno"](../modules/_yesno_.md) > [IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md)
+
+# Interface: IYesNoInterceptingOptions
+
+## Hierarchy
+
+ [IInterceptOptions](_interceptor_.iinterceptoptions.md)
+
+**↳ IYesNoInterceptingOptions**
+
+## Index
+
+### Properties
+
+* [comparatorFn](_yesno_.iyesnointerceptingoptions.md#comparatorfn)
+* [ignorePorts](_yesno_.iyesnointerceptingoptions.md#ignoreports)
+
+---
+
+## Properties
+
+
+
+### `` comparatorFn
+
+**● comparatorFn**: *[ComparatorFn](../modules/_filtering_comparator_.md#comparatorfn)*
+
+___
+
+
+### `` ignorePorts
+
+**● ignorePorts**: *`number`[]*
+
+___
+
diff --git a/docs/modules/_context_.md b/docs/modules/_context_.md
index 79d1fa6..3b0f0d9 100644
--- a/docs/modules/_context_.md
+++ b/docs/modules/_context_.md
@@ -11,6 +11,7 @@
### Interfaces
* [IInFlightRequest](../interfaces/_context_.iinflightrequest.md)
+* [IResponseForMatchingRequest](../interfaces/_context_.iresponseformatchingrequest.md)
---
diff --git a/docs/modules/_filtering_collection_.md b/docs/modules/_filtering_collection_.md
index f151591..0a52f4f 100644
--- a/docs/modules/_filtering_collection_.md
+++ b/docs/modules/_filtering_collection_.md
@@ -13,5 +13,29 @@
* [IFiltered](../interfaces/_filtering_collection_.ifiltered.md)
* [IFilteredHttpCollectionParams](../interfaces/_filtering_collection_.ifilteredhttpcollectionparams.md)
+### Type aliases
+
+* [PartialResponse](_filtering_collection_.md#partialresponse)
+* [PartialResponseForRequest](_filtering_collection_.md#partialresponseforrequest)
+
---
+## Type aliases
+
+
+
+### PartialResponse
+
+**Ƭ PartialResponse**: * `Partial`<[ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md)> & `object`
+*
+
+___
+
+
+### PartialResponseForRequest
+
+**Ƭ PartialResponseForRequest**: * [PartialResponse](_filtering_collection_.md#partialresponse) | `function`
+*
+
+___
+
diff --git a/docs/modules/_filtering_matcher_.md b/docs/modules/_filtering_matcher_.md
index 26feaf7..a45d30d 100644
--- a/docs/modules/_filtering_matcher_.md
+++ b/docs/modules/_filtering_matcher_.md
@@ -6,18 +6,25 @@
### Interfaces
+* [ISeralizedRequestResponseToMatch](../interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md)
* [ISerializedHttpPartialDeepMatch](../interfaces/_filtering_matcher_.iserializedhttppartialdeepmatch.md)
### Type aliases
* [MatchFn](_filtering_matcher_.md#matchfn)
+* [Matcher](_filtering_matcher_.md#matcher)
* [RequestQuery](_filtering_matcher_.md#requestquery)
* [ResponseQuery](_filtering_matcher_.md#responsequery)
+* [UnsafeMatchFn](_filtering_matcher_.md#unsafematchfn)
### Functions
* [match](_filtering_matcher_.md#match)
+### Object literals
+
+* [EMPTY_RESPONSE](_filtering_matcher_.md#empty_response)
+
---
## Type aliases
@@ -29,16 +36,24 @@
**Ƭ MatchFn**: *`function`*
#### Type declaration
-▸(serialized: *[ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)*): `boolean`
+▸(serialized: *[ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md)*): `boolean`
**Parameters:**
| Name | Type |
| ------ | ------ |
-| serialized | [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md) |
+| serialized | [ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md) |
**Returns:** `boolean`
+___
+
+
+### Matcher
+
+**Ƭ Matcher**: * [ISerializedHttpPartialDeepMatch](../interfaces/_filtering_matcher_.iserializedhttppartialdeepmatch.md) | [MatchFn](_filtering_matcher_.md#matchfn)
+*
+
___
@@ -57,6 +72,24 @@ ___
#### Type declaration
+___
+
+
+### UnsafeMatchFn
+
+**Ƭ UnsafeMatchFn**: *`function`*
+
+#### Type declaration
+▸(serialized: *[ISeralizedRequestResponseToMatch](../interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md)*): `boolean`
+
+**Parameters:**
+
+| Name | Type |
+| ------ | ------ |
+| serialized | [ISeralizedRequestResponseToMatch](../interfaces/_filtering_matcher_.iseralizedrequestresponsetomatch.md) |
+
+**Returns:** `boolean`
+
___
## Functions
@@ -65,7 +98,7 @@ ___
### match
-▸ **match**(fnOrPartialMatch: * [ISerializedHttpPartialDeepMatch](../interfaces/_filtering_matcher_.iserializedhttppartialdeepmatch.md) | [MatchFn](_filtering_matcher_.md#matchfn)*): `function`
+▸ **match**(fnOrPartialMatch: * [ISerializedHttpPartialDeepMatch](../interfaces/_filtering_matcher_.iserializedhttppartialdeepmatch.md) | [MatchFn](_filtering_matcher_.md#matchfn)*): [UnsafeMatchFn](_filtering_matcher_.md#unsafematchfn)
Curried function to determine whether a query matches an intercepted request.
@@ -79,7 +112,43 @@ RegEx values are tested for match.
| ------ | ------ |
| fnOrPartialMatch | [ISerializedHttpPartialDeepMatch](../interfaces/_filtering_matcher_.iserializedhttppartialdeepmatch.md) | [MatchFn](_filtering_matcher_.md#matchfn)|
-**Returns:** `function`
+**Returns:** [UnsafeMatchFn](_filtering_matcher_.md#unsafematchfn)
+
+___
+
+## Object literals
+
+
+
+### `` EMPTY_RESPONSE
+
+**EMPTY_RESPONSE**: *`object`*
+
+
+
+#### body
+
+**● body**: *`object`*
+
+#### Type declaration
+
+___
+
+
+#### headers
+
+**● headers**: *`object`*
+
+#### Type declaration
+
+___
+
+
+#### statusCode
+
+**● statusCode**: *`number`* = 0
+
+___
___
diff --git a/docs/modules/_http_serializer_.md b/docs/modules/_http_serializer_.md
index f7f80a5..559efab 100644
--- a/docs/modules/_http_serializer_.md
+++ b/docs/modules/_http_serializer_.md
@@ -14,6 +14,7 @@
* [ClientRequestFull](../interfaces/_http_serializer_.clientrequestfull.md)
* [ICreateRecord](../interfaces/_http_serializer_.icreaterecord.md)
* [IHeaders](../interfaces/_http_serializer_.iheaders.md)
+* [ISeralizedRequestResponse](../interfaces/_http_serializer_.iseralizedrequestresponse.md)
* [ISerializedHttp](../interfaces/_http_serializer_.iserializedhttp.md)
* [ISerializedRequest](../interfaces/_http_serializer_.iserializedrequest.md)
* [ISerializedResponse](../interfaces/_http_serializer_.iserializedresponse.md)
diff --git a/docs/modules/_mock_response_.md b/docs/modules/_mock_response_.md
new file mode 100644
index 0000000..ba62868
--- /dev/null
+++ b/docs/modules/_mock_response_.md
@@ -0,0 +1,26 @@
+[yesno-http](../README.md) > ["mock-response"](../modules/_mock_response_.md)
+
+# External module: "mock-response"
+
+## Index
+
+### Classes
+
+* [MockResponse](../classes/_mock_response_.mockresponse.md)
+
+### Variables
+
+* [debug](_mock_response_.md#debug)
+
+---
+
+## Variables
+
+
+
+### `` debug
+
+**● debug**: *`IDebugger`* = require('debug')('yesno:mock-response')
+
+___
+
diff --git a/docs/modules/_yesno_.md b/docs/modules/_yesno_.md
index 0084b48..89f4068 100644
--- a/docs/modules/_yesno_.md
+++ b/docs/modules/_yesno_.md
@@ -11,6 +11,7 @@
### Interfaces
* [IRecordableTest](../interfaces/_yesno_.irecordabletest.md)
+* [IYesNoInterceptingOptions](../interfaces/_yesno_.iyesnointerceptingoptions.md)
### Type aliases
diff --git a/src/filtering/collection.ts b/src/filtering/collection.ts
index 1d3e6bc..9b6105e 100644
--- a/src/filtering/collection.ts
+++ b/src/filtering/collection.ts
@@ -58,8 +58,12 @@ export default class FilteredHttpCollection implements IFiltered {
}
/**
- * Provide a mock response for all matching requests
- * @param response Serialized response or a callback to define the response per request
+ * Provide a mock response for all matching requests.
+ *
+ * Use callback to dynamically generate response per request.
+ *
+ * Matching responses defined here take _precedence_ over mocks loaded normally.
+ * @param response Serialized HTTP response or callback
*/
public respond(response: PartialResponseForRequest): void {
this.ctx.addResponseForMatchingRequests({ response, matcher: this.matcher });