4
4
5
5
import url = require( "url" ) ;
6
6
import { OutgoingHttpHeaders } from "http" ;
7
- import { merge } from "lodash" ;
7
+ import { merge , defaults } from "lodash" ;
8
8
import { Readable } from "stream" ;
9
9
import { stripIndent } from "common-tags" ;
10
10
@@ -43,7 +43,8 @@ import {
43
43
CallbackHandlerResult ,
44
44
StreamHandlerData ,
45
45
CloseConnectionHandlerData ,
46
- TimeoutHandlerData
46
+ TimeoutHandlerData ,
47
+ PassThroughHandlerOptions
47
48
} from "./handlers" ;
48
49
49
50
/**
@@ -303,6 +304,11 @@ export default class MockRuleBuilder {
303
304
* for proxied requests only, direct requests will be rejected with
304
305
* an error.
305
306
*
307
+ * This method takes options to configure how the request is passed
308
+ * through. The only option currently supported is ignoreHostCertificateErrors,
309
+ * a list of hostnames for which server certificate errors should
310
+ * be ignored (none, by default).
311
+ *
306
312
* Calling this method registers the rule with the server, so it
307
313
* starts to handle requests.
308
314
*
@@ -311,11 +317,11 @@ export default class MockRuleBuilder {
311
317
* before sending requests to be matched. The mocked endpoint
312
318
* can be used to assert on the requests matched by this rule.
313
319
*/
314
- thenPassThrough ( ) : Promise < MockedEndpoint > {
320
+ thenPassThrough ( options ?: PassThroughHandlerOptions ) : Promise < MockedEndpoint > {
315
321
const rule : MockRuleData = {
316
322
matchers : this . matchers ,
317
323
completionChecker : this . isComplete ,
318
- handler : new PassThroughHandlerData ( )
324
+ handler : new PassThroughHandlerData ( options )
319
325
} ;
320
326
321
327
return this . addRule ( rule ) ;
@@ -326,6 +332,11 @@ export default class MockRuleBuilder {
326
332
* specified must not include a path. Otherwise, an error is thrown.
327
333
* The path portion of the original request url is used instead.
328
334
*
335
+ * This method also takes options to configure how the request is passed
336
+ * through. The only option currently supported is ignoreHostCertificateErrors,
337
+ * a list of hostnames for which server certificate errors should
338
+ * be ignored (none, by default).
339
+ *
329
340
* Calling this method registers the rule with the server, so it
330
341
* starts to handle requests.
331
342
*
@@ -334,20 +345,20 @@ export default class MockRuleBuilder {
334
345
* before sending requests to be matched. The mocked endpoint
335
346
* can be used to assert on the requests matched by this rule.
336
347
*/
337
- async thenForwardTo ( forwardToUrl : string ) : Promise < MockedEndpoint > {
338
- const { protocol, hostname, port, path } = url . parse ( forwardToUrl ) ;
348
+ async thenForwardTo ( forwardToLocation : string , options ?: PassThroughHandlerOptions ) : Promise < MockedEndpoint > {
349
+ const { protocol, hostname, port, path } = url . parse ( forwardToLocation ) ;
339
350
if ( path && path . trim ( ) !== "/" ) {
340
351
const suggestion = url . format ( { protocol, hostname, port } ) ;
341
352
throw new Error ( stripIndent `
342
- URLs passed to thenForwardTo cannot include a path, but "${ forwardToUrl } " does. ${ ''
353
+ URLs passed to thenForwardTo cannot include a path, but "${ forwardToLocation } " does. ${ ''
343
354
} Did you mean ${ suggestion } ?
344
355
` ) ;
345
356
}
346
357
347
358
const rule : MockRuleData = {
348
359
matchers : this . matchers ,
349
360
completionChecker : this . isComplete ,
350
- handler : new PassThroughHandlerData ( forwardToUrl )
361
+ handler : new PassThroughHandlerData ( defaults ( { forwardToLocation } , options ) )
351
362
} ;
352
363
353
364
return this . addRule ( rule ) ;
0 commit comments