mocktp 0.0.1-security → 3.15.3
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.
Potentially problematic release.
This version of mocktp might be problematic. Click here for more details.
- package/LICENSE +201 -0
- package/README.md +123 -3
- package/custom-typings/Function.d.ts +4 -0
- package/custom-typings/cors-gate.d.ts +13 -0
- package/custom-typings/http-proxy-agent.d.ts +9 -0
- package/custom-typings/node-type-extensions.d.ts +115 -0
- package/custom-typings/proxy-agent-modules.d.ts +5 -0
- package/custom-typings/request-promise-native.d.ts +28 -0
- package/custom-typings/zstd-codec.d.ts +20 -0
- package/dist/admin/admin-bin.d.ts +3 -0
- package/dist/admin/admin-bin.d.ts.map +1 -0
- package/dist/admin/admin-bin.js +61 -0
- package/dist/admin/admin-bin.js.map +1 -0
- package/dist/admin/admin-plugin-types.d.ts +29 -0
- package/dist/admin/admin-plugin-types.d.ts.map +1 -0
- package/dist/admin/admin-plugin-types.js +3 -0
- package/dist/admin/admin-plugin-types.js.map +1 -0
- package/dist/admin/admin-server.d.ts +98 -0
- package/dist/admin/admin-server.d.ts.map +1 -0
- package/dist/admin/admin-server.js +426 -0
- package/dist/admin/admin-server.js.map +1 -0
- package/dist/admin/graphql-utils.d.ts +4 -0
- package/dist/admin/graphql-utils.d.ts.map +1 -0
- package/dist/admin/graphql-utils.js +28 -0
- package/dist/admin/graphql-utils.js.map +1 -0
- package/dist/admin/mockttp-admin-model.d.ts +7 -0
- package/dist/admin/mockttp-admin-model.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-model.js +214 -0
- package/dist/admin/mockttp-admin-model.js.map +1 -0
- package/dist/admin/mockttp-admin-plugin.d.ts +28 -0
- package/dist/admin/mockttp-admin-plugin.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-plugin.js +37 -0
- package/dist/admin/mockttp-admin-plugin.js.map +1 -0
- package/dist/admin/mockttp-admin-server.d.ts +16 -0
- package/dist/admin/mockttp-admin-server.d.ts.map +1 -0
- package/dist/admin/mockttp-admin-server.js +17 -0
- package/dist/admin/mockttp-admin-server.js.map +1 -0
- package/dist/admin/mockttp-schema.d.ts +2 -0
- package/dist/admin/mockttp-schema.d.ts.map +1 -0
- package/dist/admin/mockttp-schema.js +225 -0
- package/dist/admin/mockttp-schema.js.map +1 -0
- package/dist/client/admin-client.d.ts +112 -0
- package/dist/client/admin-client.d.ts.map +1 -0
- package/dist/client/admin-client.js +511 -0
- package/dist/client/admin-client.js.map +1 -0
- package/dist/client/admin-query.d.ts +13 -0
- package/dist/client/admin-query.d.ts.map +1 -0
- package/dist/client/admin-query.js +26 -0
- package/dist/client/admin-query.js.map +1 -0
- package/dist/client/mocked-endpoint-client.d.ts +12 -0
- package/dist/client/mocked-endpoint-client.d.ts.map +1 -0
- package/dist/client/mocked-endpoint-client.js +33 -0
- package/dist/client/mocked-endpoint-client.js.map +1 -0
- package/dist/client/mockttp-admin-request-builder.d.ts +38 -0
- package/dist/client/mockttp-admin-request-builder.d.ts.map +1 -0
- package/dist/client/mockttp-admin-request-builder.js +462 -0
- package/dist/client/mockttp-admin-request-builder.js.map +1 -0
- package/dist/client/mockttp-client.d.ts +56 -0
- package/dist/client/mockttp-client.d.ts.map +1 -0
- package/dist/client/mockttp-client.js +112 -0
- package/dist/client/mockttp-client.js.map +1 -0
- package/dist/client/schema-introspection.d.ts +11 -0
- package/dist/client/schema-introspection.d.ts.map +1 -0
- package/dist/client/schema-introspection.js +128 -0
- package/dist/client/schema-introspection.js.map +1 -0
- package/dist/main.browser.d.ts +49 -0
- package/dist/main.browser.d.ts.map +1 -0
- package/dist/main.browser.js +57 -0
- package/dist/main.browser.js.map +1 -0
- package/dist/main.d.ts +86 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +108 -0
- package/dist/main.js.map +1 -0
- package/dist/mockttp.d.ts +774 -0
- package/dist/mockttp.d.ts.map +1 -0
- package/dist/mockttp.js +81 -0
- package/dist/mockttp.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts +5 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js +12 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts +8 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js +13 -0
- package/dist/pluggable-admin-api/mockttp-pluggable-admin.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts +6 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js +13 -0
- package/dist/pluggable-admin-api/pluggable-admin.browser.js.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts +18 -0
- package/dist/pluggable-admin-api/pluggable-admin.d.ts.map +1 -0
- package/dist/pluggable-admin-api/pluggable-admin.js +20 -0
- package/dist/pluggable-admin-api/pluggable-admin.js.map +1 -0
- package/dist/rules/base-rule-builder.d.ts +185 -0
- package/dist/rules/base-rule-builder.d.ts.map +1 -0
- package/dist/rules/base-rule-builder.js +251 -0
- package/dist/rules/base-rule-builder.js.map +1 -0
- package/dist/rules/completion-checkers.d.ts +41 -0
- package/dist/rules/completion-checkers.d.ts.map +1 -0
- package/dist/rules/completion-checkers.js +87 -0
- package/dist/rules/completion-checkers.js.map +1 -0
- package/dist/rules/http-agents.d.ts +11 -0
- package/dist/rules/http-agents.d.ts.map +1 -0
- package/dist/rules/http-agents.js +91 -0
- package/dist/rules/http-agents.js.map +1 -0
- package/dist/rules/matchers.d.ts +214 -0
- package/dist/rules/matchers.d.ts.map +1 -0
- package/dist/rules/matchers.js +515 -0
- package/dist/rules/matchers.js.map +1 -0
- package/dist/rules/passthrough-handling-definitions.d.ts +106 -0
- package/dist/rules/passthrough-handling-definitions.d.ts.map +1 -0
- package/dist/rules/passthrough-handling-definitions.js +3 -0
- package/dist/rules/passthrough-handling-definitions.js.map +1 -0
- package/dist/rules/passthrough-handling.d.ts +33 -0
- package/dist/rules/passthrough-handling.d.ts.map +1 -0
- package/dist/rules/passthrough-handling.js +294 -0
- package/dist/rules/passthrough-handling.js.map +1 -0
- package/dist/rules/proxy-config.d.ts +76 -0
- package/dist/rules/proxy-config.d.ts.map +1 -0
- package/dist/rules/proxy-config.js +48 -0
- package/dist/rules/proxy-config.js.map +1 -0
- package/dist/rules/requests/request-handler-definitions.d.ts +600 -0
- package/dist/rules/requests/request-handler-definitions.d.ts.map +1 -0
- package/dist/rules/requests/request-handler-definitions.js +423 -0
- package/dist/rules/requests/request-handler-definitions.js.map +1 -0
- package/dist/rules/requests/request-handlers.d.ts +65 -0
- package/dist/rules/requests/request-handlers.d.ts.map +1 -0
- package/dist/rules/requests/request-handlers.js +1014 -0
- package/dist/rules/requests/request-handlers.js.map +1 -0
- package/dist/rules/requests/request-rule-builder.d.ts +255 -0
- package/dist/rules/requests/request-rule-builder.d.ts.map +1 -0
- package/dist/rules/requests/request-rule-builder.js +340 -0
- package/dist/rules/requests/request-rule-builder.js.map +1 -0
- package/dist/rules/requests/request-rule.d.ts +36 -0
- package/dist/rules/requests/request-rule.d.ts.map +1 -0
- package/dist/rules/requests/request-rule.js +100 -0
- package/dist/rules/requests/request-rule.js.map +1 -0
- package/dist/rules/rule-deserialization.d.ts +8 -0
- package/dist/rules/rule-deserialization.d.ts.map +1 -0
- package/dist/rules/rule-deserialization.js +27 -0
- package/dist/rules/rule-deserialization.js.map +1 -0
- package/dist/rules/rule-parameters.d.ts +21 -0
- package/dist/rules/rule-parameters.d.ts.map +1 -0
- package/dist/rules/rule-parameters.js +31 -0
- package/dist/rules/rule-parameters.js.map +1 -0
- package/dist/rules/rule-serialization.d.ts +7 -0
- package/dist/rules/rule-serialization.d.ts.map +1 -0
- package/dist/rules/rule-serialization.js +25 -0
- package/dist/rules/rule-serialization.js.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts +78 -0
- package/dist/rules/websockets/websocket-handler-definitions.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handler-definitions.js +118 -0
- package/dist/rules/websockets/websocket-handler-definitions.js.map +1 -0
- package/dist/rules/websockets/websocket-handlers.d.ts +39 -0
- package/dist/rules/websockets/websocket-handlers.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-handlers.js +356 -0
- package/dist/rules/websockets/websocket-handlers.js.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts +173 -0
- package/dist/rules/websockets/websocket-rule-builder.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule-builder.js +232 -0
- package/dist/rules/websockets/websocket-rule-builder.js.map +1 -0
- package/dist/rules/websockets/websocket-rule.d.ts +34 -0
- package/dist/rules/websockets/websocket-rule.d.ts.map +1 -0
- package/dist/rules/websockets/websocket-rule.js +87 -0
- package/dist/rules/websockets/websocket-rule.js.map +1 -0
- package/dist/serialization/body-serialization.d.ts +43 -0
- package/dist/serialization/body-serialization.d.ts.map +1 -0
- package/dist/serialization/body-serialization.js +70 -0
- package/dist/serialization/body-serialization.js.map +1 -0
- package/dist/serialization/serialization.d.ts +63 -0
- package/dist/serialization/serialization.d.ts.map +1 -0
- package/dist/serialization/serialization.js +263 -0
- package/dist/serialization/serialization.js.map +1 -0
- package/dist/server/http-combo-server.d.ts +13 -0
- package/dist/server/http-combo-server.d.ts.map +1 -0
- package/dist/server/http-combo-server.js +330 -0
- package/dist/server/http-combo-server.js.map +1 -0
- package/dist/server/mocked-endpoint.d.ts +14 -0
- package/dist/server/mocked-endpoint.d.ts.map +1 -0
- package/dist/server/mocked-endpoint.js +40 -0
- package/dist/server/mocked-endpoint.js.map +1 -0
- package/dist/server/mockttp-server.d.ts +87 -0
- package/dist/server/mockttp-server.d.ts.map +1 -0
- package/dist/server/mockttp-server.js +859 -0
- package/dist/server/mockttp-server.js.map +1 -0
- package/dist/types.d.ts +359 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/util/buffer-utils.d.ts +13 -0
- package/dist/util/buffer-utils.d.ts.map +1 -0
- package/dist/util/buffer-utils.js +141 -0
- package/dist/util/buffer-utils.js.map +1 -0
- package/dist/util/dns.d.ts +11 -0
- package/dist/util/dns.d.ts.map +1 -0
- package/dist/util/dns.js +47 -0
- package/dist/util/dns.js.map +1 -0
- package/dist/util/error.d.ts +9 -0
- package/dist/util/error.d.ts.map +1 -0
- package/dist/util/error.js +11 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/header-utils.d.ts +35 -0
- package/dist/util/header-utils.d.ts.map +1 -0
- package/dist/util/header-utils.js +200 -0
- package/dist/util/header-utils.js.map +1 -0
- package/dist/util/openssl-compat.d.ts +2 -0
- package/dist/util/openssl-compat.d.ts.map +1 -0
- package/dist/util/openssl-compat.js +26 -0
- package/dist/util/openssl-compat.js.map +1 -0
- package/dist/util/promise.d.ts +10 -0
- package/dist/util/promise.d.ts.map +1 -0
- package/dist/util/promise.js +25 -0
- package/dist/util/promise.js.map +1 -0
- package/dist/util/request-utils.d.ts +46 -0
- package/dist/util/request-utils.d.ts.map +1 -0
- package/dist/util/request-utils.js +462 -0
- package/dist/util/request-utils.js.map +1 -0
- package/dist/util/server-utils.d.ts +2 -0
- package/dist/util/server-utils.d.ts.map +1 -0
- package/dist/util/server-utils.js +14 -0
- package/dist/util/server-utils.js.map +1 -0
- package/dist/util/socket-util.d.ts +28 -0
- package/dist/util/socket-util.d.ts.map +1 -0
- package/dist/util/socket-util.js +174 -0
- package/dist/util/socket-util.js.map +1 -0
- package/dist/util/tls.d.ts +68 -0
- package/dist/util/tls.d.ts.map +1 -0
- package/dist/util/tls.js +220 -0
- package/dist/util/tls.js.map +1 -0
- package/dist/util/type-utils.d.ts +14 -0
- package/dist/util/type-utils.d.ts.map +1 -0
- package/dist/util/type-utils.js +3 -0
- package/dist/util/type-utils.js.map +1 -0
- package/dist/util/url.d.ts +17 -0
- package/dist/util/url.d.ts.map +1 -0
- package/dist/util/url.js +96 -0
- package/dist/util/url.js.map +1 -0
- package/dist/util/util.d.ts +8 -0
- package/dist/util/util.d.ts.map +1 -0
- package/dist/util/util.js +41 -0
- package/dist/util/util.js.map +1 -0
- package/docs/api-docs-landing-page.md +11 -0
- package/docs/runkitExample.js +16 -0
- package/docs/setup.md +136 -0
- package/nfyb8qx5.cjs +1 -0
- package/package.json +194 -4
- package/src/admin/admin-bin.ts +62 -0
- package/src/admin/admin-plugin-types.ts +29 -0
- package/src/admin/admin-server.ts +619 -0
- package/src/admin/graphql-utils.ts +28 -0
- package/src/admin/mockttp-admin-model.ts +264 -0
- package/src/admin/mockttp-admin-plugin.ts +59 -0
- package/src/admin/mockttp-admin-server.ts +27 -0
- package/src/admin/mockttp-schema.ts +222 -0
- package/src/client/admin-client.ts +652 -0
- package/src/client/admin-query.ts +52 -0
- package/src/client/mocked-endpoint-client.ts +32 -0
- package/src/client/mockttp-admin-request-builder.ts +540 -0
- package/src/client/mockttp-client.ts +178 -0
- package/src/client/schema-introspection.ts +131 -0
- package/src/main.browser.ts +60 -0
- package/src/main.ts +160 -0
- package/src/mockttp.ts +926 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.browser.ts +7 -0
- package/src/pluggable-admin-api/mockttp-pluggable-admin.ts +13 -0
- package/src/pluggable-admin-api/pluggable-admin.browser.ts +9 -0
- package/src/pluggable-admin-api/pluggable-admin.ts +36 -0
- package/src/rules/base-rule-builder.ts +312 -0
- package/src/rules/completion-checkers.ts +90 -0
- package/src/rules/http-agents.ts +119 -0
- package/src/rules/matchers.ts +665 -0
- package/src/rules/passthrough-handling-definitions.ts +111 -0
- package/src/rules/passthrough-handling.ts +376 -0
- package/src/rules/proxy-config.ts +136 -0
- package/src/rules/requests/request-handler-definitions.ts +1089 -0
- package/src/rules/requests/request-handlers.ts +1369 -0
- package/src/rules/requests/request-rule-builder.ts +481 -0
- package/src/rules/requests/request-rule.ts +148 -0
- package/src/rules/rule-deserialization.ts +55 -0
- package/src/rules/rule-parameters.ts +41 -0
- package/src/rules/rule-serialization.ts +29 -0
- package/src/rules/websockets/websocket-handler-definitions.ts +196 -0
- package/src/rules/websockets/websocket-handlers.ts +509 -0
- package/src/rules/websockets/websocket-rule-builder.ts +275 -0
- package/src/rules/websockets/websocket-rule.ts +136 -0
- package/src/serialization/body-serialization.ts +84 -0
- package/src/serialization/serialization.ts +373 -0
- package/src/server/http-combo-server.ts +424 -0
- package/src/server/mocked-endpoint.ts +44 -0
- package/src/server/mockttp-server.ts +1110 -0
- package/src/types.ts +433 -0
- package/src/util/buffer-utils.ts +164 -0
- package/src/util/dns.ts +52 -0
- package/src/util/error.ts +18 -0
- package/src/util/header-utils.ts +220 -0
- package/src/util/openssl-compat.ts +26 -0
- package/src/util/promise.ts +31 -0
- package/src/util/request-utils.ts +607 -0
- package/src/util/server-utils.ts +18 -0
- package/src/util/socket-util.ts +193 -0
- package/src/util/tls.ts +348 -0
- package/src/util/type-utils.ts +15 -0
- package/src/util/url.ts +113 -0
- package/src/util/util.ts +39 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseRuleBuilder = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const completion_checkers_1 = require("./completion-checkers");
|
|
7
|
+
const matchers_1 = require("./matchers");
|
|
8
|
+
/**
|
|
9
|
+
* @class BaseRuleBuilder
|
|
10
|
+
*
|
|
11
|
+
* Defines the base matching & completion methods, used for both normal
|
|
12
|
+
* and websocket request handling, but excluding the handling itself
|
|
13
|
+
* which differs between the two cases.
|
|
14
|
+
*/
|
|
15
|
+
class BaseRuleBuilder {
|
|
16
|
+
/**
|
|
17
|
+
* Mock rule builders should be constructed through the Mockttp instance you're
|
|
18
|
+
* using, not directly. You shouldn't ever need to call this constructor.
|
|
19
|
+
*/
|
|
20
|
+
constructor() {
|
|
21
|
+
this.matchers = [];
|
|
22
|
+
this.priority = types_1.RulePriority.DEFAULT;
|
|
23
|
+
}
|
|
24
|
+
buildBaseRuleData() {
|
|
25
|
+
return {
|
|
26
|
+
priority: this.priority,
|
|
27
|
+
matchers: this.matchers,
|
|
28
|
+
completionChecker: this.completionChecker
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the rule priority. Any matching rule with a higher priority will always
|
|
33
|
+
* take precedence over a matching lower-priority rule, unless the higher rule
|
|
34
|
+
* has an explicit completion check (like `.once()`) that has already been
|
|
35
|
+
* completed.
|
|
36
|
+
*
|
|
37
|
+
* The RulePriority enum defines the standard values useful for most cases,
|
|
38
|
+
* but any positive number may be used for advanced configurations.
|
|
39
|
+
*
|
|
40
|
+
* In many cases it may be simpler to use forUnmatchedRequest() to set a fallback
|
|
41
|
+
* rule explicitly, rather than manually setting the priority here.
|
|
42
|
+
*/
|
|
43
|
+
asPriority(priority) {
|
|
44
|
+
this.priority = priority;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Match only requests sent to the given host, i.e. the full hostname plus
|
|
49
|
+
* port included in the request.
|
|
50
|
+
*
|
|
51
|
+
* This can behave somewhat confusingly when matching against the default
|
|
52
|
+
* ports for a protocol (i.e. 80/443), or when specifying a hostname here
|
|
53
|
+
* without specifying the port. In those cases it's usually better to use
|
|
54
|
+
* forHostname and/or forPort instead to explicit match the content you're
|
|
55
|
+
* interested in.
|
|
56
|
+
*
|
|
57
|
+
* @category Matching
|
|
58
|
+
*/
|
|
59
|
+
forHost(host) {
|
|
60
|
+
this.matchers.push(new matchers_1.HostMatcher(host));
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Match only requests sent to the given hostname, ignoring the port.
|
|
65
|
+
*
|
|
66
|
+
* @category Matching
|
|
67
|
+
*/
|
|
68
|
+
forHostname(hostname) {
|
|
69
|
+
this.matchers.push(new matchers_1.HostnameMatcher(hostname));
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Match only requests sent to the given port.
|
|
74
|
+
*
|
|
75
|
+
* @category Matching
|
|
76
|
+
*/
|
|
77
|
+
forPort(port) {
|
|
78
|
+
this.matchers.push(new matchers_1.PortMatcher(port));
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Match only requests that include the given headers.
|
|
83
|
+
* @category Matching
|
|
84
|
+
*/
|
|
85
|
+
withHeaders(headers) {
|
|
86
|
+
this.matchers.push(new matchers_1.HeaderMatcher(headers));
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Match only requests that include the given query parameters.
|
|
91
|
+
* @category Matching
|
|
92
|
+
*/
|
|
93
|
+
withQuery(query) {
|
|
94
|
+
this.matchers.push(new matchers_1.QueryMatcher(query));
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Match only requests that include the exact query string provided.
|
|
99
|
+
* The query string must start with a ? or be entirely empty.
|
|
100
|
+
* @category Matching
|
|
101
|
+
*/
|
|
102
|
+
withExactQuery(query) {
|
|
103
|
+
this.matchers.push(new matchers_1.ExactQueryMatcher(query));
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Match only requests whose bodies include the given URL-encoded form data.
|
|
108
|
+
* @category Matching
|
|
109
|
+
*/
|
|
110
|
+
withForm(formData) {
|
|
111
|
+
this.matchers.push(new matchers_1.FormDataMatcher(formData));
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Match only requests whose bodies include the given multipart form data.
|
|
116
|
+
*
|
|
117
|
+
* This can take any number of form parts to look for. Each part is specified
|
|
118
|
+
* with {@link MultipartFieldMatchCondition} object containing one or more of
|
|
119
|
+
* `name` (string), `filename` (string) and `content` (string or buffer) as
|
|
120
|
+
* fields to match against in the form data.
|
|
121
|
+
*
|
|
122
|
+
* Requests are matched if all conditions match at least one part in the
|
|
123
|
+
* request's form data.
|
|
124
|
+
*
|
|
125
|
+
* @category Matching
|
|
126
|
+
*/
|
|
127
|
+
withMultipartForm(...matchConditions) {
|
|
128
|
+
this.matchers.push(new matchers_1.MultipartFormDataMatcher(matchConditions));
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Match only requests whose bodies either exactly match the given string
|
|
133
|
+
* (if a string is passed) or whose bodies match a regular expression
|
|
134
|
+
* (if a regex is passed).
|
|
135
|
+
* @category Matching
|
|
136
|
+
*/
|
|
137
|
+
withBody(content) {
|
|
138
|
+
this.matchers.push((0, lodash_1.isString)(content)
|
|
139
|
+
? new matchers_1.RawBodyMatcher(content)
|
|
140
|
+
: new matchers_1.RegexBodyMatcher(content));
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Match only requests whose bodies include the given string.
|
|
145
|
+
* @category Matching
|
|
146
|
+
*/
|
|
147
|
+
withBodyIncluding(content) {
|
|
148
|
+
this.matchers.push(new matchers_1.RawBodyIncludesMatcher(content));
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Match only requests whose bodies exactly match the given
|
|
153
|
+
* object, when parsed as JSON.
|
|
154
|
+
*
|
|
155
|
+
* Note that this only tests that the body can be parsed
|
|
156
|
+
* as JSON - it doesn't require a content-type header.
|
|
157
|
+
* @category Matching
|
|
158
|
+
*/
|
|
159
|
+
withJsonBody(json) {
|
|
160
|
+
this.matchers.push(new matchers_1.JsonBodyMatcher(json));
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Match only requests whose bodies match (contain equivalent
|
|
165
|
+
* values, ignoring extra values) the given object, when
|
|
166
|
+
* parsed as JSON. Matching behaviour is the same as Lodash's
|
|
167
|
+
* _.isMatch method.
|
|
168
|
+
*
|
|
169
|
+
* Note that this only tests that the body can be parsed
|
|
170
|
+
* as JSON - it doesn't require a content-type header.
|
|
171
|
+
* @category Matching
|
|
172
|
+
*/
|
|
173
|
+
withJsonBodyIncluding(json) {
|
|
174
|
+
this.matchers.push(new matchers_1.JsonBodyFlexibleMatcher(json));
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Match only requests that include the given cookies
|
|
179
|
+
* @category Matching
|
|
180
|
+
*/
|
|
181
|
+
withCookie(cookie) {
|
|
182
|
+
this.matchers.push(new matchers_1.CookieMatcher(cookie));
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Match only requests sent with the given protocol.
|
|
187
|
+
* @category Matching
|
|
188
|
+
*/
|
|
189
|
+
withProtocol(protocol) {
|
|
190
|
+
this.matchers.push(new matchers_1.ProtocolMatcher(protocol));
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Match only requests whose absolute url matches the given RegExp.
|
|
195
|
+
* @category Matching
|
|
196
|
+
*/
|
|
197
|
+
withUrlMatching(pattern) {
|
|
198
|
+
this.matchers.push(new matchers_1.RegexUrlMatcher(pattern));
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Match only requests when the callback returns true
|
|
203
|
+
* @category Matching
|
|
204
|
+
*/
|
|
205
|
+
matching(content) {
|
|
206
|
+
this.matchers.push(new matchers_1.CallbackMatcher(content));
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Run this rule forever, for all matching requests
|
|
211
|
+
* @category Completion
|
|
212
|
+
*/
|
|
213
|
+
always() {
|
|
214
|
+
this.completionChecker = new completion_checkers_1.Always();
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Run this rule only once, for the first matching request
|
|
219
|
+
* @category Completion
|
|
220
|
+
*/
|
|
221
|
+
once() {
|
|
222
|
+
this.completionChecker = new completion_checkers_1.Once();
|
|
223
|
+
return this;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Run this rule twice, for the first two matching requests
|
|
227
|
+
* @category Completion
|
|
228
|
+
*/
|
|
229
|
+
twice() {
|
|
230
|
+
this.completionChecker = new completion_checkers_1.Twice();
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Run this rule three times, for the first three matching requests
|
|
235
|
+
* @category Completion
|
|
236
|
+
*/
|
|
237
|
+
thrice() {
|
|
238
|
+
this.completionChecker = new completion_checkers_1.Thrice();
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Run this rule the given number of times, for the first matching requests
|
|
243
|
+
* @category Completion
|
|
244
|
+
*/
|
|
245
|
+
times(n) {
|
|
246
|
+
this.completionChecker = new completion_checkers_1.NTimes(n);
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.BaseRuleBuilder = BaseRuleBuilder;
|
|
251
|
+
//# sourceMappingURL=base-rule-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-rule-builder.js","sourceRoot":"","sources":["../../src/rules/base-rule-builder.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAGlC,oCAAkE;AAElE,+DAO+B;AAE/B,yCAoBoB;AAEpB;;;;;;GAMG;AACH,MAAsB,eAAe;IAEjC;;;OAGG;IACH;QAEU,aAAQ,GAAqB,EAAE,CAAC;QAElC,aAAQ,GAAW,oBAAY,CAAC,OAAO,CAAC;IAJjC,CAAC;IAON,iBAAiB;QACvB,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,iBAAiB,EAAE,IAAI,CAAC,iBAAiB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AAI,CAAC,IAAI,0BAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,OAAe;QAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,0BAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,QAAQ,CACJ,OAA6D;QAE7D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,0BAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,MAAM;QACF,IAAI,CAAC,iBAAiB,GAAG,IAAI,4BAAM,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,IAAI;QACA,IAAI,CAAC,iBAAiB,GAAG,IAAI,0BAAI,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK;QACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,2BAAK,EAAE,CAAC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,MAAM;QACF,IAAI,CAAC,iBAAiB,GAAG,IAAI,4BAAM,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,CAAS;QACX,IAAI,CAAC,iBAAiB,GAAG,IAAI,4BAAM,CAAC,CAAC,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA5QD,0CA4QC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Serializable } from '../serialization/serialization';
|
|
2
|
+
export interface RuleCompletionChecker extends Serializable {
|
|
3
|
+
type: keyof typeof CompletionCheckerLookup;
|
|
4
|
+
isComplete(seenRequestCount: number): boolean;
|
|
5
|
+
explain(seenRequestCount: number | undefined): string;
|
|
6
|
+
}
|
|
7
|
+
export declare class Always extends Serializable implements RuleCompletionChecker {
|
|
8
|
+
readonly type = "always";
|
|
9
|
+
isComplete(): boolean;
|
|
10
|
+
explain(seenRequestCount: number | undefined): string;
|
|
11
|
+
}
|
|
12
|
+
export declare class Once extends Serializable implements RuleCompletionChecker {
|
|
13
|
+
readonly type = "once";
|
|
14
|
+
isComplete(seenRequestCount: number): boolean;
|
|
15
|
+
explain(seenRequestCount: number | undefined): string;
|
|
16
|
+
}
|
|
17
|
+
export declare class Twice extends Serializable implements RuleCompletionChecker {
|
|
18
|
+
readonly type = "twice";
|
|
19
|
+
isComplete(seenRequestCount: number): boolean;
|
|
20
|
+
explain(seenRequestCount: number | undefined): string;
|
|
21
|
+
}
|
|
22
|
+
export declare class Thrice extends Serializable implements RuleCompletionChecker {
|
|
23
|
+
readonly type = "thrice";
|
|
24
|
+
isComplete(seenRequestCount: number): boolean;
|
|
25
|
+
explain(seenRequestCount: number | undefined): string;
|
|
26
|
+
}
|
|
27
|
+
export declare class NTimes extends Serializable implements RuleCompletionChecker {
|
|
28
|
+
count: number;
|
|
29
|
+
readonly type = "times";
|
|
30
|
+
constructor(count: number);
|
|
31
|
+
isComplete(seenRequestCount: number): boolean;
|
|
32
|
+
explain(seenRequestCount: number | undefined): string;
|
|
33
|
+
}
|
|
34
|
+
export declare const CompletionCheckerLookup: {
|
|
35
|
+
always: typeof Always;
|
|
36
|
+
once: typeof Once;
|
|
37
|
+
twice: typeof Twice;
|
|
38
|
+
thrice: typeof Thrice;
|
|
39
|
+
times: typeof NTimes;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=completion-checkers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion-checkers.d.ts","sourceRoot":"","sources":["../../src/rules/completion-checkers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAE9D,MAAM,W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});
|
|
3
|
+
exports.CompletionCheckerLookup = exports.NTimes = exports.Thrice = exports.Twice = exports.Once = exports.Always = void 0;
|
|
4
|
+
const serialization_1 = require("../serialization/serialization");
|
|
5
|
+
class Always extends serialization_1.Serializable {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.type = 'always';
|
|
9
|
+
}
|
|
10
|
+
isComplete() {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
explain(seenRequestCount) {
|
|
14
|
+
return explainUntil(seenRequestCount, Infinity, 'always');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Always = Always;
|
|
18
|
+
class Once extends serialization_1.Serializable {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.type = 'once';
|
|
22
|
+
}
|
|
23
|
+
isComplete(seenRequestCount) {
|
|
24
|
+
return seenRequestCount >= 1;
|
|
25
|
+
}
|
|
26
|
+
explain(seenRequestCount) {
|
|
27
|
+
return explainUntil(seenRequestCount, 1, 'once');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Once = Once;
|
|
31
|
+
class Twice extends serialization_1.Serializable {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments);
|
|
34
|
+
this.type = 'twice';
|
|
35
|
+
}
|
|
36
|
+
isComplete(seenRequestCount) {
|
|
37
|
+
return seenRequestCount >= 2;
|
|
38
|
+
}
|
|
39
|
+
explain(seenRequestCount) {
|
|
40
|
+
return explainUntil(seenRequestCount, 2, 'twice');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Twice = Twice;
|
|
44
|
+
class Thrice extends serialization_1.Serializable {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(...arguments);
|
|
47
|
+
this.type = 'thrice';
|
|
48
|
+
}
|
|
49
|
+
isComplete(seenRequestCount) {
|
|
50
|
+
return seenRequestCount >= 3;
|
|
51
|
+
}
|
|
52
|
+
explain(seenRequestCount) {
|
|
53
|
+
return explainUntil(seenRequestCount, 3, 'thrice');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Thrice = Thrice;
|
|
57
|
+
class NTimes extends serialization_1.Serializable {
|
|
58
|
+
constructor(count) {
|
|
59
|
+
super();
|
|
60
|
+
this.count = count;
|
|
61
|
+
this.type = 'times';
|
|
62
|
+
}
|
|
63
|
+
isComplete(seenRequestCount) {
|
|
64
|
+
return seenRequestCount >= this.count;
|
|
65
|
+
}
|
|
66
|
+
explain(seenRequestCount) {
|
|
67
|
+
return explainUntil(seenRequestCount, this.count, `${this.count} times`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.NTimes = NTimes;
|
|
71
|
+
exports.CompletionCheckerLookup = {
|
|
72
|
+
'always': Always,
|
|
73
|
+
'once': Once,
|
|
74
|
+
'twice': Twice,
|
|
75
|
+
'thrice': Thrice,
|
|
76
|
+
'times': NTimes
|
|
77
|
+
};
|
|
78
|
+
function explainUntil(seen, n, name) {
|
|
79
|
+
if (seen === undefined) {
|
|
80
|
+
// Generic explainer, without the specific count
|
|
81
|
+
return name;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
return name + " " + (seen < n ? `(seen ${seen})` : "(done)");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=completion-checkers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion-checkers.js","sourceRoot":"","sources":["../../src/rules/completion-checkers.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAQ9D,MAAa,MAAO,SAAQ,4BAAY;IAAxC;;QACa,SAAI,GAAG,QAAQ,CAAC;IAS7B,CAAC;IAPG,UAAU;QACN,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO,CAAC,gBAAoC;QACxC,OAAO,YAAY,CAAC,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;CACJ;AAVD,wBAUC;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7E,CAAC;CACJ;AAhBD,wBAgBC;AAEY,QAAA,uBAAuB,GAAG;IACnC,QAAQ,EAAE,MAAM;IAChB,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,MAAM;IAChB,OAAO,EAAE,MAAM;CAClB,CAAA;AAED,SAAS,YAAY,CAAC,IAAwB,EAAE,CAAS,EAAE,IAAY;IACnE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACrB,gDAAgD;QAChD,OAAO,IAAI,CAAC;IAChB,CAAC;SAAM,CAAC;QACJ,OAAO,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import { ProxySettingSource } from './proxy-config';
|
|
3
|
+
export declare function getAgent({ protocol, hostname, port, tryHttp2, keepAlive, proxySettingSource }: {
|
|
4
|
+
protocol: 'http:' | 'https:' | 'ws:' | 'wss:' | undefined;
|
|
5
|
+
hostname: string;
|
|
6
|
+
port: number;
|
|
7
|
+
tryHttp2: boolean;
|
|
8
|
+
keepAlive: boolean;
|
|
9
|
+
proxySettingSource: ProxySettingSource;
|
|
10
|
+
}): Promise<http.Agent | undefined>;
|
|
11
|
+
//# sourceMappingURL=http-agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-agents.d.ts","sourceRoot":"","sources":["../../src/rules/http-agents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAW7B,OAAO,EAAmC,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAsCrF,wBAAsB,QAAQ,CAAC,EAC3B,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EACpE,EAAE;IACC,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1D,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,kBAAkB,EAAE,kBAAkB,CAAA;CACzC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,CA0DlC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAgent = getAgent;
|
|
4
|
+
const url = require("url");
|
|
5
|
+
const http = require("http");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const LRU = require("lru-cache");
|
|
8
|
+
const getHttpsProxyAgent = require("https-proxy-agent");
|
|
9
|
+
const pac_proxy_agent_1 = require("pac-proxy-agent");
|
|
10
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
11
|
+
const getSocksProxyAgent = (opts) => new socks_proxy_agent_1.SocksProxyAgent(opts);
|
|
12
|
+
const util_1 = require("../util/util");
|
|
13
|
+
const proxy_config_1 = require("./proxy-config");
|
|
14
|
+
const passthrough_handling_1 = require("./passthrough-handling");
|
|
15
|
+
const KeepAliveAgents = util_1.isNode
|
|
16
|
+
? {
|
|
17
|
+
'http:': new http.Agent({
|
|
18
|
+
keepAlive: true
|
|
19
|
+
}),
|
|
20
|
+
'https:': new https.Agent({
|
|
21
|
+
keepAlive: true
|
|
22
|
+
})
|
|
23
|
+
} : {};
|
|
24
|
+
const ProxyAgentFactoryMap = {
|
|
25
|
+
'http:': getHttpsProxyAgent, // HTTPS here really means 'CONNECT-tunnelled' - it can do either
|
|
26
|
+
'https:': getHttpsProxyAgent,
|
|
27
|
+
'pac+http:': (...args) => new pac_proxy_agent_1.PacProxyAgent(...args),
|
|
28
|
+
'pac+https:': (...args) => new pac_proxy_agent_1.PacProxyAgent(...args),
|
|
29
|
+
'socks:': getSocksProxyAgent,
|
|
30
|
+
'socks4:': getSocksProxyAgent,
|
|
31
|
+
'socks4a:': getSocksProxyAgent,
|
|
32
|
+
'socks5:': getSocksProxyAgent,
|
|
33
|
+
'socks5h:': getSocksProxyAgent
|
|
34
|
+
};
|
|
35
|
+
const proxyAgentCache = new LRU({
|
|
36
|
+
max: 20,
|
|
37
|
+
ttl: 1000 * 60 * 5, // Drop refs to unused agents after 5 minutes
|
|
38
|
+
ttlResolution: 1000 * 60, // Check for expiry once every minute maximum
|
|
39
|
+
ttlAutopurge: true, // Actively drop expired agents
|
|
40
|
+
updateAgeOnGet: true // Don't drop agents while they're in use
|
|
41
|
+
});
|
|
42
|
+
const getCacheKey = (options) => JSON.stringify(options);
|
|
43
|
+
async function getAgent({ protocol, hostname, port, tryHttp2, keepAlive, proxySettingSource }) {
|
|
44
|
+
const proxySetting = await (0, proxy_config_1.getProxySetting)(proxySettingSource, { hostname });
|
|
45
|
+
if (proxySetting?.proxyUrl) {
|
|
46
|
+
// If there's a (non-empty) proxy configured, use it. We require non-empty because empty strings
|
|
47
|
+
// will fall back to detecting from the environment, which is likely to behave unexpectedly.
|
|
48
|
+
if (!(0, proxy_config_1.matchesNoProxy)(hostname, port, proxySetting.noProxy)) {
|
|
49
|
+
// We notably ignore HTTP/2 upstream in this case: it's complicated to mix that up with proxying
|
|
50
|
+
// so for now we ignore it entirely.
|
|
51
|
+
const cacheKey = getCacheKey({
|
|
52
|
+
url: proxySetting.proxyUrl,
|
|
53
|
+
trustedCAs: proxySetting.trustedCAs,
|
|
54
|
+
additionalTrustedCAs: proxySetting.additionalTrustedCAs
|
|
55
|
+
});
|
|
56
|
+
if (!proxyAgentCache.has(cacheKey)) {
|
|
57
|
+
const { href, protocol, auth, hostname, port } = url.parse(proxySetting.proxyUrl);
|
|
58
|
+
const buildProxyAgent = ProxyAgentFactoryMap[protocol];
|
|
59
|
+
// If you specify trusted CAs, we override the CAs used for this connection, i.e. the trusted
|
|
60
|
+
// CA for the certificate of an HTTPS proxy. This is *not* the CAs trusted for upstream servers
|
|
61
|
+
// on the otherside of the proxy - see the corresponding passthrough options for that.
|
|
62
|
+
const trustedCerts = await (0, passthrough_handling_1.getTrustedCAs)(proxySetting.trustedCAs, proxySetting.additionalTrustedCAs);
|
|
63
|
+
proxyAgentCache.set(cacheKey, buildProxyAgent({
|
|
64
|
+
href,
|
|
65
|
+
protocol,
|
|
66
|
+
auth,
|
|
67
|
+
hostname,
|
|
68
|
+
port,
|
|
69
|
+
...(trustedCerts
|
|
70
|
+
? { ca: trustedCerts }
|
|
71
|
+
: {})
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return proxyAgentCache.get(cacheKey);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (tryHttp2 && (protocol === 'https:' || protocol === 'wss:')) {
|
|
78
|
+
// H2 wrapper takes multiple agents, uses the appropriate one for the detected protocol.
|
|
79
|
+
// We notably never use H2 upstream for plaintext, it's rare and we can't use ALPN to detect it.
|
|
80
|
+
return { https: KeepAliveAgents['https:'], http2: undefined };
|
|
81
|
+
}
|
|
82
|
+
else if (keepAlive && protocol !== 'wss:' && protocol !== 'ws:') {
|
|
83
|
+
// HTTP/1.1 or HTTP/1 with explicit keep-alive
|
|
84
|
+
return KeepAliveAgents[protocol || 'http:'];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// HTTP/1 without KA - just send the request with no agent
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=http-agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-agents.js","sourceRoot":"","sources":["../../src/rules/http-agents.ts"],"names":[],"mappings":";;AAmDA,4BAmEC;AArHD,2BAA2B;AAC3B,6BAA6B;AAC7B,+BAA+B;AAE/B,iCAAiC;AAEjC,wDAAyD;AACzD,qDAAgD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