@mbtest/mountebank 2.9.2-beta.9050

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -0
  3. package/bin/mb +136 -0
  4. package/package.json +71 -0
  5. package/releases.json +52 -0
  6. package/src/cli/api.js +112 -0
  7. package/src/cli/cli.js +420 -0
  8. package/src/controllers/configController.js +64 -0
  9. package/src/controllers/feedController.js +115 -0
  10. package/src/controllers/homeController.js +58 -0
  11. package/src/controllers/imposterController.js +328 -0
  12. package/src/controllers/impostersController.js +215 -0
  13. package/src/controllers/logsController.js +52 -0
  14. package/src/models/behaviors.js +553 -0
  15. package/src/models/behaviorsValidator.js +186 -0
  16. package/src/models/compatibility.js +133 -0
  17. package/src/models/dryRunValidator.js +261 -0
  18. package/src/models/filesystemBackedImpostersRepository.js +908 -0
  19. package/src/models/http/baseHttpServer.js +207 -0
  20. package/src/models/http/headersMap.js +87 -0
  21. package/src/models/http/httpProxy.js +230 -0
  22. package/src/models/http/httpRequest.js +82 -0
  23. package/src/models/http/httpServer.js +18 -0
  24. package/src/models/http/index.js +18 -0
  25. package/src/models/https/cert/mb-cert.pem +20 -0
  26. package/src/models/https/cert/mb-csr.pem +16 -0
  27. package/src/models/https/cert/mb-key.pem +27 -0
  28. package/src/models/https/httpsServer.js +42 -0
  29. package/src/models/https/index.js +18 -0
  30. package/src/models/imposter.js +243 -0
  31. package/src/models/imposterPrinter.js +120 -0
  32. package/src/models/impostersRepository.js +49 -0
  33. package/src/models/inMemoryImpostersRepository.js +418 -0
  34. package/src/models/jsonpath.js +44 -0
  35. package/src/models/mbConnection.js +107 -0
  36. package/src/models/predicates.js +438 -0
  37. package/src/models/protocols.js +242 -0
  38. package/src/models/responseResolver.js +398 -0
  39. package/src/models/smtp/index.js +16 -0
  40. package/src/models/smtp/smtpRequest.js +60 -0
  41. package/src/models/smtp/smtpServer.js +109 -0
  42. package/src/models/tcp/index.js +18 -0
  43. package/src/models/tcp/tcpProxy.js +110 -0
  44. package/src/models/tcp/tcpRequest.js +23 -0
  45. package/src/models/tcp/tcpServer.js +156 -0
  46. package/src/models/tcp/tcpValidator.js +19 -0
  47. package/src/models/xpath.js +95 -0
  48. package/src/mountebank.js +245 -0
  49. package/src/public/images/arrow_down.png +0 -0
  50. package/src/public/images/arrow_up.png +0 -0
  51. package/src/public/images/book.jpg +0 -0
  52. package/src/public/images/dataflow.png +0 -0
  53. package/src/public/images/favicon.ico +0 -0
  54. package/src/public/images/forkme_right_orange_ff7600.png +0 -0
  55. package/src/public/images/mountebank.png +0 -0
  56. package/src/public/images/overview.gif +0 -0
  57. package/src/public/images/quote.png +0 -0
  58. package/src/public/images/tw-logo.png +0 -0
  59. package/src/public/scripts/jquery/jquery-3.6.1.min.js +2 -0
  60. package/src/public/scripts/urlHashHandler.js +31 -0
  61. package/src/public/stylesheets/application.css +424 -0
  62. package/src/public/stylesheets/ie.css +14 -0
  63. package/src/public/stylesheets/imposters.css +121 -0
  64. package/src/public/stylesheets/jqueryui/1.10.4/themes/smoothness/jquery-ui.css +1178 -0
  65. package/src/util/combinators.js +68 -0
  66. package/src/util/date.js +51 -0
  67. package/src/util/errors.js +55 -0
  68. package/src/util/helpers.js +131 -0
  69. package/src/util/inherit.js +28 -0
  70. package/src/util/ip.js +54 -0
  71. package/src/util/logger.js +83 -0
  72. package/src/util/middleware.js +256 -0
  73. package/src/util/scopedLogger.js +47 -0
  74. package/src/views/_footer.ejs +20 -0
  75. package/src/views/_header.ejs +113 -0
  76. package/src/views/_imposter.ejs +8 -0
  77. package/src/views/config.ejs +71 -0
  78. package/src/views/docs/api/behaviors/copy.ejs +427 -0
  79. package/src/views/docs/api/behaviors/decorate.ejs +182 -0
  80. package/src/views/docs/api/behaviors/lookup.ejs +220 -0
  81. package/src/views/docs/api/behaviors/shellTransform.ejs +153 -0
  82. package/src/views/docs/api/behaviors/wait.ejs +121 -0
  83. package/src/views/docs/api/behaviors.ejs +141 -0
  84. package/src/views/docs/api/contracts/addStub-description.ejs +10 -0
  85. package/src/views/docs/api/contracts/addStub.ejs +10 -0
  86. package/src/views/docs/api/contracts/config-description.ejs +32 -0
  87. package/src/views/docs/api/contracts/config.ejs +23 -0
  88. package/src/views/docs/api/contracts/home-description.ejs +18 -0
  89. package/src/views/docs/api/contracts/home.ejs +13 -0
  90. package/src/views/docs/api/contracts/imposter-description.ejs +439 -0
  91. package/src/views/docs/api/contracts/imposter.ejs +182 -0
  92. package/src/views/docs/api/contracts/imposters-description.ejs +13 -0
  93. package/src/views/docs/api/contracts/imposters.ejs +13 -0
  94. package/src/views/docs/api/contracts/logs-description.ejs +3 -0
  95. package/src/views/docs/api/contracts/logs.ejs +14 -0
  96. package/src/views/docs/api/contracts/stub-description.ejs +4 -0
  97. package/src/views/docs/api/contracts/stub.ejs +7 -0
  98. package/src/views/docs/api/contracts/stubs-description.ejs +4 -0
  99. package/src/views/docs/api/contracts/stubs.ejs +11 -0
  100. package/src/views/docs/api/contracts.ejs +133 -0
  101. package/src/views/docs/api/errors.ejs +64 -0
  102. package/src/views/docs/api/fault/connectionReset.ejs +31 -0
  103. package/src/views/docs/api/fault/randomDataThenClose.ejs +31 -0
  104. package/src/views/docs/api/faults.ejs +57 -0
  105. package/src/views/docs/api/injection.ejs +426 -0
  106. package/src/views/docs/api/json.ejs +205 -0
  107. package/src/views/docs/api/jsonpath.ejs +210 -0
  108. package/src/views/docs/api/mocks.ejs +130 -0
  109. package/src/views/docs/api/overview.ejs +968 -0
  110. package/src/views/docs/api/predicates/and.ejs +62 -0
  111. package/src/views/docs/api/predicates/contains.ejs +64 -0
  112. package/src/views/docs/api/predicates/deepEquals.ejs +114 -0
  113. package/src/views/docs/api/predicates/endsWith.ejs +66 -0
  114. package/src/views/docs/api/predicates/equals.ejs +125 -0
  115. package/src/views/docs/api/predicates/exists.ejs +118 -0
  116. package/src/views/docs/api/predicates/inject.ejs +67 -0
  117. package/src/views/docs/api/predicates/matches.ejs +66 -0
  118. package/src/views/docs/api/predicates/not.ejs +52 -0
  119. package/src/views/docs/api/predicates/or.ejs +79 -0
  120. package/src/views/docs/api/predicates/startsWith.ejs +62 -0
  121. package/src/views/docs/api/predicates.ejs +382 -0
  122. package/src/views/docs/api/proxies.ejs +191 -0
  123. package/src/views/docs/api/proxy/addDecorateBehavior.ejs +115 -0
  124. package/src/views/docs/api/proxy/addWaitBehavior.ejs +96 -0
  125. package/src/views/docs/api/proxy/injectHeaders.ejs +91 -0
  126. package/src/views/docs/api/proxy/predicateGenerators.ejs +600 -0
  127. package/src/views/docs/api/proxy/proxyModes.ejs +495 -0
  128. package/src/views/docs/api/stubs.ejs +391 -0
  129. package/src/views/docs/api/xpath.ejs +281 -0
  130. package/src/views/docs/cli/configFiles.ejs +133 -0
  131. package/src/views/docs/cli/customFormatters.ejs +53 -0
  132. package/src/views/docs/cli/help.ejs +6 -0
  133. package/src/views/docs/cli/replay.ejs +42 -0
  134. package/src/views/docs/cli/restart.ejs +10 -0
  135. package/src/views/docs/cli/save.ejs +68 -0
  136. package/src/views/docs/cli/start.ejs +234 -0
  137. package/src/views/docs/cli/stop.ejs +32 -0
  138. package/src/views/docs/commandLine.ejs +93 -0
  139. package/src/views/docs/communityExtensions.ejs +233 -0
  140. package/src/views/docs/gettingStarted.ejs +146 -0
  141. package/src/views/docs/mentalModel.ejs +51 -0
  142. package/src/views/docs/protocols/custom.ejs +231 -0
  143. package/src/views/docs/protocols/http.ejs +238 -0
  144. package/src/views/docs/protocols/https.ejs +246 -0
  145. package/src/views/docs/protocols/smtp.ejs +142 -0
  146. package/src/views/docs/protocols/tcp.ejs +431 -0
  147. package/src/views/docs/security.ejs +38 -0
  148. package/src/views/faqs.ejs +65 -0
  149. package/src/views/feed.ejs +33 -0
  150. package/src/views/imposter.ejs +22 -0
  151. package/src/views/imposters.ejs +33 -0
  152. package/src/views/index.ejs +89 -0
  153. package/src/views/license.ejs +30 -0
  154. package/src/views/logs.ejs +77 -0
  155. package/src/views/releases/v1.1.0.ejs +55 -0
  156. package/src/views/releases/v1.1.36.ejs +84 -0
  157. package/src/views/releases/v1.1.72.ejs +92 -0
  158. package/src/views/releases/v1.10.0.ejs +108 -0
  159. package/src/views/releases/v1.11.0.ejs +109 -0
  160. package/src/views/releases/v1.12.0.ejs +96 -0
  161. package/src/views/releases/v1.13.0.ejs +118 -0
  162. package/src/views/releases/v1.14.0.ejs +107 -0
  163. package/src/views/releases/v1.14.1.ejs +94 -0
  164. package/src/views/releases/v1.15.0.ejs +113 -0
  165. package/src/views/releases/v1.16.0.ejs +104 -0
  166. package/src/views/releases/v1.2.0.ejs +78 -0
  167. package/src/views/releases/v1.2.103.ejs +86 -0
  168. package/src/views/releases/v1.2.122.ejs +86 -0
  169. package/src/views/releases/v1.2.30.ejs +84 -0
  170. package/src/views/releases/v1.2.45.ejs +84 -0
  171. package/src/views/releases/v1.2.56.ejs +79 -0
  172. package/src/views/releases/v1.3.0.ejs +86 -0
  173. package/src/views/releases/v1.3.1.ejs +100 -0
  174. package/src/views/releases/v1.4.0.ejs +96 -0
  175. package/src/views/releases/v1.4.1.ejs +103 -0
  176. package/src/views/releases/v1.4.2.ejs +100 -0
  177. package/src/views/releases/v1.4.3.ejs +113 -0
  178. package/src/views/releases/v1.5.0.ejs +104 -0
  179. package/src/views/releases/v1.5.1.ejs +91 -0
  180. package/src/views/releases/v1.6.0.ejs +109 -0
  181. package/src/views/releases/v1.7.0.ejs +113 -0
  182. package/src/views/releases/v1.7.1.ejs +90 -0
  183. package/src/views/releases/v1.7.2.ejs +96 -0
  184. package/src/views/releases/v1.8.0.ejs +121 -0
  185. package/src/views/releases/v1.9.0.ejs +111 -0
  186. package/src/views/releases/v2.0.0.ejs +159 -0
  187. package/src/views/releases/v2.1.0.ejs +121 -0
  188. package/src/views/releases/v2.1.1.ejs +106 -0
  189. package/src/views/releases/v2.1.2.ejs +84 -0
  190. package/src/views/releases/v2.2.0.ejs +115 -0
  191. package/src/views/releases/v2.2.1.ejs +102 -0
  192. package/src/views/releases/v2.3.0.ejs +121 -0
  193. package/src/views/releases/v2.3.1.ejs +100 -0
  194. package/src/views/releases/v2.3.2.ejs +102 -0
  195. package/src/views/releases/v2.3.3.ejs +97 -0
  196. package/src/views/releases/v2.4.0.ejs +114 -0
  197. package/src/views/releases/v2.5.0.ejs +51 -0
  198. package/src/views/releases/v2.6.0.ejs +35 -0
  199. package/src/views/releases/v2.7.0.ejs +32 -0
  200. package/src/views/releases/v2.8.0.ejs +36 -0
  201. package/src/views/releases/v2.8.1.ejs +7 -0
  202. package/src/views/releases/v2.8.2.ejs +26 -0
  203. package/src/views/releases/v2.9.0.ejs +32 -0
  204. package/src/views/releases/v2.9.1.ejs +10 -0
  205. package/src/views/releases.ejs +26 -0
  206. package/src/views/sitemap.ejs +36 -0
  207. package/src/views/support.ejs +14 -0
@@ -0,0 +1,495 @@
1
+ <p>The <code>mode</code> defines the behavior of the proxy.</p>
2
+
3
+ <ul class='bullet-list'>
4
+ <li><code>proxyOnce</code> - ensures that the same request (defined
5
+ by the predicates) is never proxied twice. mountebank only records
6
+ one response for each request, and automatically replays that response the next
7
+ time the request predicates match.</li>
8
+ <li><code>proxyAlways</code> - All calls will be proxied, allowing multiple responses
9
+ to be saved for the same logical request. You have to explicitly tell mountebank
10
+ to replay those responses.</li>
11
+ <li><code>proxyTransparent</code> - All calls will be proxied, but will not be recorded.</li>
12
+ </ul>
13
+
14
+ <h3>proxyOnce</h3>
15
+
16
+ <p>The default <code>proxyOnce</code> mode is simpler; it always creates a new
17
+ stub in front of the stub with the proxy response, relying on mountebank's first-match
18
+ policy to automatically replay the saved response in the new stub the next time a request
19
+ matches the predicates. Imagine the following <code>stubs</code> array, set by us when we
20
+ create the imposter:</p>
21
+
22
+ <testScenario name='proxyOnce'>
23
+ <step type='http'>
24
+ <code class='hidden'>POST /imposters HTTP/1.1
25
+ Host: localhost:<%= port %>
26
+ Content-Type: application/json
27
+
28
+ {
29
+ "port": 2001,
30
+ "protocol": "http",
31
+ "stubs": [{ "responses": [{ "is": { "body": "Downstream service response" } }] }]
32
+ }</code>
33
+ </step>
34
+
35
+ <step type='http'>
36
+ <pre><code><span class='hidden'>POST /imposters HTTP/1.1
37
+ Host: localhost:<%= port %>
38
+ Content-Type: application/json
39
+
40
+ {
41
+ "port": 2000,
42
+ "protocol": "http",
43
+ </span>"stubs": [{
44
+ "responses": [{
45
+ "proxy": {
46
+ "to": "<change to='http://localhost:2001'>http://origin-server.com</change>",
47
+ <strong class='highlight1'>"mode": "proxyOnce"</strong>,
48
+ "predicateGenerators": [{ "matches": { "path": true } }]
49
+ }
50
+ }]
51
+ }]<span class='hidden'>}</span></code></pre>
52
+ </step>
53
+
54
+ <p>When we issue an HTTP call to <code>/test</code>, the stub will proxy all of the request
55
+ details to http://origin-server.com/test, and save off the response in a new stub in front of the
56
+ stub with the <code>proxy</code> response:</p>
57
+
58
+ <step type='http'>
59
+ <code class='hidden'>GET /test HTTP/1.1
60
+ Host: localhost:2000</code>
61
+ </step>
62
+
63
+ <step type='http'>
64
+ <code class='hidden'>DELETE /imposters/2001 HTTP/1.1
65
+ Host: localhost:<%= port %>
66
+ Accept: application/json</code>
67
+ </step>
68
+
69
+ <step type='http'>
70
+ <code class='hidden'>DELETE /imposters/2000 HTTP/1.1
71
+ Host: localhost:<%= port %>
72
+ Accept: application/json</code>
73
+
74
+ <assertResponse partial='true'>
75
+ <pre><code><span class='hidden'>{
76
+ </span>"stubs": [
77
+ {
78
+ "predicates": [{ "deepEquals": { "path": "/test" } } ],
79
+ "responses": [<strong class='highlight1'>{
80
+ "is": {
81
+ "body": "Downstream service response",
82
+ <change to='"_mode": "text"'>...</change>
83
+ }
84
+ }</strong>]
85
+ },
86
+ {
87
+ "responses": [{
88
+ "proxy": {
89
+ "to": "http://localhost:2001",
90
+ "mode": "proxyOnce",
91
+ "predicateGenerators": [{ "matches": { "path": true } }]
92
+ }
93
+ }]
94
+ }
95
+ ]<span class='hidden'>}</span></code></pre>
96
+ </assertResponse>
97
+ </step>
98
+ </testScenario>
99
+
100
+ <p>Because of mountebank's first-match policy on stubs, the next
101
+ time the imposter receives a request to <code>/test</code>, the saved predicates on the
102
+ newly created stub will match, and the recorded response will be replayed. If
103
+ the imposter receives a call to <code>/different-path</code>, then it will proxy again,
104
+ creating a new stub, because the <code>path</code> is different.</p>
105
+
106
+ <h3>proxyAlways</h3>
107
+
108
+ <p>The <code>proxyAlways</code> mode saves stubs <em>behind</em> the <code>proxy</code>
109
+ stub. This allows you to record a richer set of interactions with the origin server
110
+ because it can record multiple responses for the same logical request (as defined by
111
+ the predicates). The consequence is that it requires you to save off the imposter representation
112
+ and remove or reorder the <code>proxy</code> stubs to replay those interactions. The easiest
113
+ way to do that is with the <a href='/docs/commandLine#replay'><code>mb replay</code></a> command.</p>
114
+
115
+ <p>Let's say you had the following <code>stubs</code> array:</p>
116
+
117
+ <testScenario name='proxyAlways'>
118
+ <step type='http'>
119
+ <code class='hidden'>POST /imposters HTTP/1.1
120
+ Host: localhost:<%= port %>
121
+ Content-Type: application/json
122
+
123
+ {
124
+ "port": 4001,
125
+ "protocol": "http",
126
+ "stubs": [{
127
+ "responses": [{
128
+ "inject": "function (req, state) { state.count = state.count || 0; state.count +=1; return { body: 'Request number ' + state.count }; }"
129
+ }]
130
+ }]
131
+ }</code>
132
+ </step>
133
+
134
+ <step type='http'>
135
+ <pre><code><span class='hidden'>POST /imposters HTTP/1.1
136
+ Host: localhost:<%= port %>
137
+ Content-Type: application/json
138
+
139
+ {
140
+ "port": 4000,
141
+ "protocol": "http",
142
+ </span>"stubs": [{
143
+ "responses": [{
144
+ "proxy": {
145
+ "to": "<change to='http://localhost:4001'>http://origin-server.com</change>",
146
+ <strong class='highlight1'>"mode": "proxyAlways"</strong>,
147
+ "predicateGenerators": [{ "matches": { "path": true } }]
148
+ }
149
+ }]
150
+ }]<span class='hidden'>}</span></code></pre>
151
+ </step>
152
+
153
+ <p>Every time we send a request to <code>/test</code>, it will
154
+ be proxied to http://origin-server.com/test. The first time we do that, just like the
155
+ <code>proxyOnce</code> example, it will add a new stub. The difference is that the
156
+ new stub will be created at the end of the array:</p>
157
+
158
+ <step type='http'>
159
+ <code class='hidden'>GET /test HTTP/1.1
160
+ Host: localhost:4000</code>
161
+ </step>
162
+
163
+ <step type='http'>
164
+ <code class='hidden'>GET /imposters/4000 HTTP/1.1
165
+ Host: localhost:<%= port %>
166
+ Accept: application/json</code>
167
+
168
+ <assertResponse partial='true'>
169
+ <pre><code><span class='hidden'>{
170
+ </span>"stubs": [
171
+ {
172
+ "responses": [
173
+ {
174
+ "proxy": {
175
+ "to": "<change to='http://localhost:4001'>http://origin-server.com</change>",
176
+ "mode": "proxyAlways",
177
+ "predicateGenerators": [{ "matches": { "path": true } }]
178
+ }
179
+ }
180
+ ]
181
+ },
182
+ {
183
+ "predicates": [{ "deepEquals": { "path": "/test" } }],
184
+ "responses": [<strong class='highlight1'>{
185
+ "is": {
186
+ "body": "Request number 1",
187
+ <change to='"_mode": "text"'>...</change>
188
+ }
189
+ }</strong>]
190
+ }
191
+ ]<span class='hidden'>}</span></code></pre>
192
+ </assertResponse>
193
+ </step>
194
+
195
+ <p>Because the proxy occurs before the new stub, the next request will continue to use
196
+ the <code>proxy</code> response. This allow us to capture multiple responses for the
197
+ same logical request. If we once again send a request to the <code>/test</code> path,
198
+ since a stub with the predicate already exists, the response will be added to the
199
+ existing stub:</p>
200
+
201
+ <step type='http'>
202
+ <code class='hidden'>GET /test HTTP/1.1
203
+ Host: localhost:4000</code>
204
+ </step>
205
+
206
+ <step type='http'>
207
+ <code class='hidden'>GET /imposters/4000 HTTP/1.1
208
+ Host: localhost:<%= port %>
209
+ Accept: application/json</code>
210
+
211
+ <assertResponse partial='true'>
212
+ <pre><code><span class='hidden'>{
213
+ </span>"stubs": [
214
+ {
215
+ "responses": [
216
+ {
217
+ "proxy": {
218
+ "to": "<change to='http://localhost:4001'>http://origin-server.com</change>",
219
+ "mode": "proxyAlways",
220
+ "predicateGenerators": [{ "matches": { "path": true } }]
221
+ }
222
+ }
223
+ ]
224
+ },
225
+ {
226
+ "predicates": [{ "deepEquals": { "path": "/test" } }],
227
+ "responses": [
228
+ {
229
+ "is": {
230
+ "body": "Request number 1",
231
+ <change to='"_mode": "text"'>...</change>
232
+ }
233
+ },
234
+ <strong class='highlight1'>{
235
+ "is": {
236
+ "body": "Request number 2",
237
+ <change to='"_mode": "text"'>...</change>
238
+ }
239
+ }</strong>
240
+ ]
241
+ }
242
+ ]<span class='hidden'>}</span></code></pre>
243
+ </assertResponse>
244
+ </step>
245
+
246
+ <p>This configuration allows you to capture as rich a set of data as your downstream
247
+ system provides and play it back with the appropriate predicates. The only additional
248
+ complexity with <code>proxyAlways</code> is that <em>you have to explicitly switch to
249
+ replay mode.</em> Conceptually, replaying is as simple as removing the proxies. The easiest
250
+ way to do that is by using the <a href='/docs/commandLine'><code>mb replay</code></a>
251
+ command, passing in the port if you're using a nonstandard port for running <code>mb</code>. If,
252
+ for example, we had previously started mountebank on port 3535,
253
+ we could switch to replay mode with the following call:</p>
254
+
255
+ <pre><code>mb replay --port 3535</code></pre>
256
+
257
+ <p class='info-icon'>As always, there's more than one way to do it. You can instead use the API,
258
+ retrieving all imposters with a call to
259
+ <a href='/docs/api/overview#get-imposters'><code>GET /imposters?replayabe=true&removeProxies=true</code></a>
260
+ and sending the payload in a call <a href='/docs/api/overview#put-imposters'>
261
+ <code>PUT /imposters</code></a>.</p>
262
+
263
+ <p>Now if we look at the imposter configuration, you'll notice that the proxy has
264
+ been removed. Only the saved responses will be used.</p>
265
+
266
+ <step type='http'>
267
+ <code class='hidden'>GET /imposters/4000?replayable=true&removeProxies=true
268
+ Host: localhost: <%= port %>
269
+ Accept: application/json</code>
270
+
271
+ <assertResponse>
272
+ <code class='hidden'>HTTP/1.1 200 OK
273
+ Vary: Accept
274
+ Content-Type: application/json; charset=utf-8
275
+ Content-Length: 896
276
+ Date: <volatile>Sat, 20 May 2017 14:43:12 GMT</volatile>
277
+ Connection: keep-alive
278
+
279
+ {
280
+ "protocol": "http",
281
+ "port": 4000,
282
+ "recordRequests": false,
283
+ "stubs": [{
284
+ "predicates": [{ "deepEquals": { "path": "/test" } }],
285
+ "responses": [
286
+ {
287
+ "is": {
288
+ "statusCode": 200,
289
+ "headers": {
290
+ "Connection": "close",
291
+ "Date": "<volatile>Sat, 20 May 2017 14:43:12 GMT</volatile>",
292
+ "Transfer-Encoding": "chunked"
293
+ },
294
+ "body": "Request number 1",
295
+ "_mode": "text"
296
+ }
297
+ },
298
+ {
299
+ "is": {
300
+ "statusCode": 200,
301
+ "headers": {
302
+ "Connection": "close",
303
+ "Date": "<volatile>Sat, 20 May 2017 14:43:12 GMT</volatile>",
304
+ "Transfer-Encoding": "chunked"
305
+ },
306
+ "body": "Request number 2",
307
+ "_mode": "text"
308
+ }
309
+ }
310
+ ]
311
+ }]
312
+ }</code>
313
+ </assertResponse>
314
+ </step>
315
+
316
+ <step type='http'>
317
+ <code class='hidden'>DELETE /imposters/4000 HTTP/1.1
318
+ Host: localhost:<%= port %>
319
+ Accept: application/json</code>
320
+ </step>
321
+
322
+ <step type='http'>
323
+ <code class='hidden'>POST /imposters HTTP/1.1
324
+ Host: localhost:<%= port %>
325
+ Accept: application/json
326
+
327
+ {
328
+ "protocol": "http",
329
+ "port": 4000,
330
+ "stubs": [
331
+ {
332
+ "predicates": [
333
+ {
334
+ "deepEquals": {
335
+ "path": "/test"
336
+ }
337
+ }
338
+ ],
339
+ "responses": [
340
+ {
341
+ "is": {
342
+ "statusCode": 200,
343
+ "headers": {
344
+ "Connection": "close",
345
+ "Date": "Fri, 19 May 2017 01:09:42 GMT",
346
+ "Transfer-Encoding": "chunked"
347
+ },
348
+ "body": "Request number 1",
349
+ "_mode": "text",
350
+ "_proxyResponseTime": 14
351
+ }
352
+ },
353
+ {
354
+ "is": {
355
+ "statusCode": 200,
356
+ "headers": {
357
+ "Connection": "close",
358
+ "Date": "Fri, 19 May 2017 01:09:42 GMT",
359
+ "Transfer-Encoding": "chunked"
360
+ },
361
+ "body": "Request number 2",
362
+ "_mode": "text",
363
+ "_proxyResponseTime": 4
364
+ }
365
+ }
366
+ ]
367
+ }
368
+ ]
369
+ }</code>
370
+ </assertResponse>
371
+ </step>
372
+
373
+ <step type='http'>
374
+ <code class='hidden'>GET /imposters/4000 HTTP/1.1
375
+ Host: localhost:<%= port %>
376
+ Accept: application/json</code>
377
+
378
+ <assertResponse partial='true'>
379
+ <pre><code><span class='hidden'>{
380
+ </span>"stubs": [
381
+ {
382
+ "predicates": [{ "deepEquals": { "path": "/test" } }],
383
+ "responses": [
384
+ {
385
+ "is": {
386
+ "body": "Request number 1",
387
+ <change to='"_mode": "text"'>...</change>
388
+ }
389
+ },
390
+ {
391
+ "is": {
392
+ "body": "Request number 2",
393
+ <change to='"_mode": "text"'>...</change>
394
+ }
395
+ }
396
+ ]
397
+ }
398
+ ]<span class='hidden'>}</span></code></pre>
399
+ </assertResponse>
400
+ </step>
401
+
402
+ <step type='http'>
403
+ <code class='hidden'>DELETE /imposters/4000 HTTP/1.1
404
+ Host: localhost:<%= port %>
405
+ Accept: application/json</code>
406
+ </step>
407
+
408
+ <step type='http'>
409
+ <code class='hidden'>DELETE /imposters/4001 HTTP/1.1
410
+ Host: localhost:<%= port %>
411
+ Accept: application/json</code>
412
+ </step>
413
+ </testScenario>
414
+
415
+
416
+ <h3>proxyTransparent</h3>
417
+
418
+ <p>The <code>proxyTransparent</code> mode does not save any responses and simply proxies the
419
+ requests transparently.</p>
420
+
421
+ <p>Let's say you had the following <code>stubs</code> array:</p>
422
+
423
+ <testScenario name='proxyTransparent'>
424
+
425
+ <step type='http'>
426
+ <code class='hidden'>POST /imposters HTTP/1.1
427
+ Host: localhost:<%= port %>
428
+ Content-Type: application/json
429
+
430
+ {
431
+ "port": 4002,
432
+ "protocol": "http"
433
+ }</code>
434
+ </step>
435
+
436
+ <step type='http'>
437
+ <pre><code><span class='hidden'>POST /imposters HTTP/1.1
438
+ Host: localhost:<%= port %>
439
+ Content-Type: application/json
440
+
441
+ {
442
+ "port": 5050,
443
+ "protocol": "http",
444
+ </span>"stubs": [{
445
+ "responses": [{
446
+ "proxy": {
447
+ "to": "<change to='http://localhost:4002'>http://origin-server.com</change>",
448
+ <strong class='highlight1'>"mode": "proxyTransparent"</strong>
449
+ }
450
+ }]
451
+ }]<span class='hidden'>}</span></code></pre>
452
+ </step>
453
+
454
+ <p>Every time we send a request to <code>/test</code>, it will
455
+ be proxied to http://origin-server.com/test. There will be no stub created off the back of the request.</p>
456
+
457
+ <step type='http'>
458
+ <code class='hidden'>GET /test HTTP/1.1
459
+ Host: localhost:5050</code>
460
+ </step>
461
+
462
+ <step type='http'>
463
+ <code class='hidden'>GET /imposters/5050 HTTP/1.1
464
+ Host: localhost:<%= port %>
465
+ Accept: application/json</code>
466
+
467
+ <assertResponse partial='true'>
468
+ <code class='hidden'>{
469
+ "stubs": [
470
+ {
471
+ "responses": [
472
+ {
473
+ "proxy": {
474
+ "to": "<change to='http://localhost:4002'>http://origin-server.com</change>",
475
+ "mode": "proxyTransparent"
476
+ }
477
+ }
478
+ ]
479
+ }
480
+ ]}</code>
481
+ </assertResponse>
482
+ </step>
483
+
484
+ <step type='http'>
485
+ <code class='hidden'>DELETE /imposters/4002 HTTP/1.1
486
+ Host: localhost:<%= port %>
487
+ Accept: application/json</code>
488
+ </step>
489
+
490
+ <step type='http'>
491
+ <code class='hidden'>DELETE /imposters/5050 HTTP/1.1
492
+ Host: localhost:<%= port %>
493
+ Accept: application/json</code>
494
+ </step>
495
+ </testScenario>