@@ -534,6 +534,31 @@ export interface PassThroughHandlerOptions {
534
534
*/
535
535
lookupOptions ?: PassThroughLookupOptions ;
536
536
537
+ /**
538
+ * Whether to simulate connection errors back to the client.
539
+ *
540
+ * By default (in most cases - see below) when an upstream request fails
541
+ * outright a 502 "Bad Gateway" response is sent to the downstream client,
542
+ * explicitly indicating the failure and containing the error that caused
543
+ * the issue in the response body.
544
+ *
545
+ * Only in the case of upstream connection reset errors is a connection reset
546
+ * normally sent back downstream to existing clients (this behaviour exists
547
+ * for backward compatibility, and will change to match other error behaviour
548
+ * in a future version).
549
+ *
550
+ * When this option is set to `true`, low-level connection failures will
551
+ * always trigger a downstream connection close/reset, rather than a 502
552
+ * response.
553
+ *
554
+ * This includes DNS failures, TLS connection errors, TCP connection resets,
555
+ * etc (but not HTTP non-200 responses, which are still proxied as normal).
556
+ * This is less convenient for debugging in a testing environment or when
557
+ * using a proxy intentionally, but can be more accurate when trying to
558
+ * transparently proxy network traffic, errors and all.
559
+ */
560
+ simulateConnectionErrors ?: boolean ;
561
+
537
562
/**
538
563
* A set of data to automatically transform a request. This includes properties
539
564
* to support many transformation common use cases.
@@ -724,6 +749,7 @@ export interface SerializedPassThroughData {
724
749
extraCACertificates ?: Array < { cert : string } | { certPath : string } > ;
725
750
clientCertificateHostMap ?: { [ host : string ] : { pfx : string , passphrase ?: string } } ;
726
751
lookupOptions ?: PassThroughLookupOptions ;
752
+ simulateConnectionErrors ?: boolean ;
727
753
728
754
transformRequest ?: Replace < RequestTransform , {
729
755
'replaceBody' ?: string , // Serialized as base64 buffer
@@ -792,6 +818,8 @@ export class PassThroughHandlerDefinition extends Serializable implements Reques
792
818
793
819
public readonly lookupOptions ?: PassThroughLookupOptions ;
794
820
821
+ public readonly simulateConnectionErrors : boolean ;
822
+
795
823
// Used in subclass - awkwardly needs to be initialized here to ensure that its set when using a
796
824
// handler built from a definition. In future, we could improve this (compose instead of inheritance
797
825
// to better control handler construction?) but this will do for now.
@@ -823,6 +851,7 @@ export class PassThroughHandlerDefinition extends Serializable implements Reques
823
851
824
852
this . lookupOptions = options . lookupOptions ;
825
853
this . proxyConfig = options . proxyConfig ;
854
+ this . simulateConnectionErrors = ! ! options . simulateConnectionErrors ;
826
855
827
856
this . clientCertificateHostMap = options . clientCertificateHostMap || { } ;
828
857
this . extraCACertificates = options . trustAdditionalCAs || [ ] ;
@@ -932,6 +961,7 @@ export class PassThroughHandlerDefinition extends Serializable implements Reques
932
961
} : { } ,
933
962
proxyConfig : serializeProxyConfig ( this . proxyConfig , channel ) ,
934
963
lookupOptions : this . lookupOptions ,
964
+ simulateConnectionErrors : this . simulateConnectionErrors ,
935
965
ignoreHostCertificateErrors : this . ignoreHostHttpsErrors ,
936
966
extraCACertificates : this . extraCACertificates . map ( ( certObject ) => {
937
967
// We use toString to make sure that buffers always end up as
0 commit comments