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.

Files changed (304) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +123 -3
  3. package/custom-typings/Function.d.ts +4 -0
  4. package/custom-typings/cors-gate.d.ts +13 -0
  5. package/custom-typings/http-proxy-agent.d.ts +9 -0
  6. package/custom-typings/node-type-extensions.d.ts +115 -0
  7. package/custom-typings/proxy-agent-modules.d.ts +5 -0
  8. package/custom-typings/request-promise-native.d.ts +28 -0
  9. package/custom-typings/zstd-codec.d.ts +20 -0
  10. package/dist/admin/admin-bin.d.ts +3 -0
  11. package/dist/admin/admin-bin.d.ts.map +1 -0
  12. package/dist/admin/admin-bin.js +61 -0
  13. package/dist/admin/admin-bin.js.map +1 -0
  14. package/dist/admin/admin-plugin-types.d.ts +29 -0
  15. package/dist/admin/admin-plugin-types.d.ts.map +1 -0
  16. package/dist/admin/admin-plugin-types.js +3 -0
  17. package/dist/admin/admin-plugin-types.js.map +1 -0
  18. package/dist/admin/admin-server.d.ts +98 -0
  19. package/dist/admin/admin-server.d.ts.map +1 -0
  20. package/dist/admin/admin-server.js +426 -0
  21. package/dist/admin/admin-server.js.map +1 -0
  22. package/dist/admin/graphql-utils.d.ts +4 -0
  23. package/dist/admin/graphql-utils.d.ts.map +1 -0
  24. package/dist/admin/graphql-utils.js +28 -0
  25. package/dist/admin/graphql-utils.js.map +1 -0
  26. package/dist/admin/mockttp-admin-model.d.ts +7 -0
  27. package/dist/admin/mockttp-admin-model.d.ts.map +1 -0
  28. package/dist/admin/mockttp-admin-model.js +214 -0
  29. package/dist/admin/mockttp-admin-model.js.map +1 -0
  30. package/dist/admin/mockttp-admin-plugin.d.ts +28 -0
  31. package/dist/admin/mockttp-admin-plugin.d.ts.map +1 -0
  32. package/dist/admin/mockttp-admin-plugin.js +37 -0
  33. package/dist/admin/mockttp-admin-plugin.js.map +1 -0
  34. package/dist/admin/mockttp-admin-server.d.ts +16 -0
  35. package/dist/admin/mockttp-admin-server.d.ts.map +1 -0
  36. package/dist/admin/mockttp-admin-server.js +17 -0
  37. package/dist/admin/mockttp-admin-server.js.map +1 -0
  38. package/dist/admin/mockttp-schema.d.ts +2 -0
  39. package/dist/admin/mockttp-schema.d.ts.map +1 -0
  40. package/dist/admin/mockttp-schema.js +225 -0
  41. package/dist/admin/mockttp-schema.js.map +1 -0
  42. package/dist/client/admin-client.d.ts +112 -0
  43. package/dist/client/admin-client.d.ts.map +1 -0
  44. package/dist/client/admin-client.js +511 -0
  45. package/dist/client/admin-client.js.map +1 -0
  46. package/dist/client/admin-query.d.ts +13 -0
  47. package/dist/client/admin-query.d.ts.map +1 -0
  48. package/dist/client/admin-query.js +26 -0
  49. package/dist/client/admin-query.js.map +1 -0
  50. package/dist/client/mocked-endpoint-client.d.ts +12 -0
  51. package/dist/client/mocked-endpoint-client.d.ts.map +1 -0
  52. package/dist/client/mocked-endpoint-client.js +33 -0
  53. package/dist/client/mocked-endpoint-client.js.map +1 -0
  54. package/dist/client/mockttp-admin-request-builder.d.ts +38 -0
  55. package/dist/client/mockttp-admin-request-builder.d.ts.map +1 -0
  56. package/dist/client/mockttp-admin-request-builder.js +462 -0
  57. package/dist/client/mockttp-admin-request-builder.js.map +1 -0
  58. package/dist/client/mockttp-client.d.ts +56 -0
  59. package/dist/client/mockttp-client.d.ts.map +1 -0
  60. package/dist/client/mockttp-client.js +112 -0
  61. package/dist/client/mockttp-client.js.map +1 -0
  62. package/dist/client/schema-introspection.d.ts +11 -0
  63. package/dist/client/schema-introspection.d.ts.map +1 -0
  64. package/dist/client/schema-introspection.js +128 -0
  65. package/dist/client/schema-introspection.js.map +1 -0
  66. package/dist/main.browser.d.ts +49 -0
  67. package/dist/main.browser.d.ts.map +1 -0
  68. package/dist/main.browser.js +57 -0
  69. package/dist/main.browser.js.map +1 -0
  70. package/dist/main.d.ts +86 -0
  71. package/dist/main.d.ts.map +1 -0
  72. package/dist/main.js +108 -0
  73. package/dist/main.js.map +1 -0
  74. package/dist/mockttp.d.ts +774 -0
  75. package/dist/mockttp.d.ts.map +1 -0
  76. package/dist/mockttp.js +81 -0
  77. package/dist/mockttp.js.map +1 -0
  78. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts +5 -0
  79. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.d.ts.map +1 -0
  80. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js +12 -0
  81. package/dist/pluggable-admin-api/mockttp-pluggable-admin.browser.js.map +1 -0
  82. package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts +8 -0
  83. package/dist/pluggable-admin-api/mockttp-pluggable-admin.d.ts.map +1 -0
  84. package/dist/pluggable-admin-api/mockttp-pluggable-admin.js +13 -0
  85. package/dist/pluggable-admin-api/mockttp-pluggable-admin.js.map +1 -0
  86. package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts +6 -0
  87. package/dist/pluggable-admin-api/pluggable-admin.browser.d.ts.map +1 -0
  88. package/dist/pluggable-admin-api/pluggable-admin.browser.js +13 -0
  89. package/dist/pluggable-admin-api/pluggable-admin.browser.js.map +1 -0
  90. package/dist/pluggable-admin-api/pluggable-admin.d.ts +18 -0
  91. package/dist/pluggable-admin-api/pluggable-admin.d.ts.map +1 -0
  92. package/dist/pluggable-admin-api/pluggable-admin.js +20 -0
  93. package/dist/pluggable-admin-api/pluggable-admin.js.map +1 -0
  94. package/dist/rules/base-rule-builder.d.ts +185 -0
  95. package/dist/rules/base-rule-builder.d.ts.map +1 -0
  96. package/dist/rules/base-rule-builder.js +251 -0
  97. package/dist/rules/base-rule-builder.js.map +1 -0
  98. package/dist/rules/completion-checkers.d.ts +41 -0
  99. package/dist/rules/completion-checkers.d.ts.map +1 -0
  100. package/dist/rules/completion-checkers.js +87 -0
  101. package/dist/rules/completion-checkers.js.map +1 -0
  102. package/dist/rules/http-agents.d.ts +11 -0
  103. package/dist/rules/http-agents.d.ts.map +1 -0
  104. package/dist/rules/http-agents.js +91 -0
  105. package/dist/rules/http-agents.js.map +1 -0
  106. package/dist/rules/matchers.d.ts +214 -0
  107. package/dist/rules/matchers.d.ts.map +1 -0
  108. package/dist/rules/matchers.js +515 -0
  109. package/dist/rules/matchers.js.map +1 -0
  110. package/dist/rules/passthrough-handling-definitions.d.ts +106 -0
  111. package/dist/rules/passthrough-handling-definitions.d.ts.map +1 -0
  112. package/dist/rules/passthrough-handling-definitions.js +3 -0
  113. package/dist/rules/passthrough-handling-definitions.js.map +1 -0
  114. package/dist/rules/passthrough-handling.d.ts +33 -0
  115. package/dist/rules/passthrough-handling.d.ts.map +1 -0
  116. package/dist/rules/passthrough-handling.js +294 -0
  117. package/dist/rules/passthrough-handling.js.map +1 -0
  118. package/dist/rules/proxy-config.d.ts +76 -0
  119. package/dist/rules/proxy-config.d.ts.map +1 -0
  120. package/dist/rules/proxy-config.js +48 -0
  121. package/dist/rules/proxy-config.js.map +1 -0
  122. package/dist/rules/requests/request-handler-definitions.d.ts +600 -0
  123. package/dist/rules/requests/request-handler-definitions.d.ts.map +1 -0
  124. package/dist/rules/requests/request-handler-definitions.js +423 -0
  125. package/dist/rules/requests/request-handler-definitions.js.map +1 -0
  126. package/dist/rules/requests/request-handlers.d.ts +65 -0
  127. package/dist/rules/requests/request-handlers.d.ts.map +1 -0
  128. package/dist/rules/requests/request-handlers.js +1014 -0
  129. package/dist/rules/requests/request-handlers.js.map +1 -0
  130. package/dist/rules/requests/request-rule-builder.d.ts +255 -0
  131. package/dist/rules/requests/request-rule-builder.d.ts.map +1 -0
  132. package/dist/rules/requests/request-rule-builder.js +340 -0
  133. package/dist/rules/requests/request-rule-builder.js.map +1 -0
  134. package/dist/rules/requests/request-rule.d.ts +36 -0
  135. package/dist/rules/requests/request-rule.d.ts.map +1 -0
  136. package/dist/rules/requests/request-rule.js +100 -0
  137. package/dist/rules/requests/request-rule.js.map +1 -0
  138. package/dist/rules/rule-deserialization.d.ts +8 -0
  139. package/dist/rules/rule-deserialization.d.ts.map +1 -0
  140. package/dist/rules/rule-deserialization.js +27 -0
  141. package/dist/rules/rule-deserialization.js.map +1 -0
  142. package/dist/rules/rule-parameters.d.ts +21 -0
  143. package/dist/rules/rule-parameters.d.ts.map +1 -0
  144. package/dist/rules/rule-parameters.js +31 -0
  145. package/dist/rules/rule-parameters.js.map +1 -0
  146. package/dist/rules/rule-serialization.d.ts +7 -0
  147. package/dist/rules/rule-serialization.d.ts.map +1 -0
  148. package/dist/rules/rule-serialization.js +25 -0
  149. package/dist/rules/rule-serialization.js.map +1 -0
  150. package/dist/rules/websockets/websocket-handler-definitions.d.ts +78 -0
  151. package/dist/rules/websockets/websocket-handler-definitions.d.ts.map +1 -0
  152. package/dist/rules/websockets/websocket-handler-definitions.js +118 -0
  153. package/dist/rules/websockets/websocket-handler-definitions.js.map +1 -0
  154. package/dist/rules/websockets/websocket-handlers.d.ts +39 -0
  155. package/dist/rules/websockets/websocket-handlers.d.ts.map +1 -0
  156. package/dist/rules/websockets/websocket-handlers.js +356 -0
  157. package/dist/rules/websockets/websocket-handlers.js.map +1 -0
  158. package/dist/rules/websockets/websocket-rule-builder.d.ts +173 -0
  159. package/dist/rules/websockets/websocket-rule-builder.d.ts.map +1 -0
  160. package/dist/rules/websockets/websocket-rule-builder.js +232 -0
  161. package/dist/rules/websockets/websocket-rule-builder.js.map +1 -0
  162. package/dist/rules/websockets/websocket-rule.d.ts +34 -0
  163. package/dist/rules/websockets/websocket-rule.d.ts.map +1 -0
  164. package/dist/rules/websockets/websocket-rule.js +87 -0
  165. package/dist/rules/websockets/websocket-rule.js.map +1 -0
  166. package/dist/serialization/body-serialization.d.ts +43 -0
  167. package/dist/serialization/body-serialization.d.ts.map +1 -0
  168. package/dist/serialization/body-serialization.js +70 -0
  169. package/dist/serialization/body-serialization.js.map +1 -0
  170. package/dist/serialization/serialization.d.ts +63 -0
  171. package/dist/serialization/serialization.d.ts.map +1 -0
  172. package/dist/serialization/serialization.js +263 -0
  173. package/dist/serialization/serialization.js.map +1 -0
  174. package/dist/server/http-combo-server.d.ts +13 -0
  175. package/dist/server/http-combo-server.d.ts.map +1 -0
  176. package/dist/server/http-combo-server.js +330 -0
  177. package/dist/server/http-combo-server.js.map +1 -0
  178. package/dist/server/mocked-endpoint.d.ts +14 -0
  179. package/dist/server/mocked-endpoint.d.ts.map +1 -0
  180. package/dist/server/mocked-endpoint.js +40 -0
  181. package/dist/server/mocked-endpoint.js.map +1 -0
  182. package/dist/server/mockttp-server.d.ts +87 -0
  183. package/dist/server/mockttp-server.d.ts.map +1 -0
  184. package/dist/server/mockttp-server.js +859 -0
  185. package/dist/server/mockttp-server.js.map +1 -0
  186. package/dist/types.d.ts +359 -0
  187. package/dist/types.d.ts.map +1 -0
  188. package/dist/types.js +20 -0
  189. package/dist/types.js.map +1 -0
  190. package/dist/util/buffer-utils.d.ts +13 -0
  191. package/dist/util/buffer-utils.d.ts.map +1 -0
  192. package/dist/util/buffer-utils.js +141 -0
  193. package/dist/util/buffer-utils.js.map +1 -0
  194. package/dist/util/dns.d.ts +11 -0
  195. package/dist/util/dns.d.ts.map +1 -0
  196. package/dist/util/dns.js +47 -0
  197. package/dist/util/dns.js.map +1 -0
  198. package/dist/util/error.d.ts +9 -0
  199. package/dist/util/error.d.ts.map +1 -0
  200. package/dist/util/error.js +11 -0
  201. package/dist/util/error.js.map +1 -0
  202. package/dist/util/header-utils.d.ts +35 -0
  203. package/dist/util/header-utils.d.ts.map +1 -0
  204. package/dist/util/header-utils.js +200 -0
  205. package/dist/util/header-utils.js.map +1 -0
  206. package/dist/util/openssl-compat.d.ts +2 -0
  207. package/dist/util/openssl-compat.d.ts.map +1 -0
  208. package/dist/util/openssl-compat.js +26 -0
  209. package/dist/util/openssl-compat.js.map +1 -0
  210. package/dist/util/promise.d.ts +10 -0
  211. package/dist/util/promise.d.ts.map +1 -0
  212. package/dist/util/promise.js +25 -0
  213. package/dist/util/promise.js.map +1 -0
  214. package/dist/util/request-utils.d.ts +46 -0
  215. package/dist/util/request-utils.d.ts.map +1 -0
  216. package/dist/util/request-utils.js +462 -0
  217. package/dist/util/request-utils.js.map +1 -0
  218. package/dist/util/server-utils.d.ts +2 -0
  219. package/dist/util/server-utils.d.ts.map +1 -0
  220. package/dist/util/server-utils.js +14 -0
  221. package/dist/util/server-utils.js.map +1 -0
  222. package/dist/util/socket-util.d.ts +28 -0
  223. package/dist/util/socket-util.d.ts.map +1 -0
  224. package/dist/util/socket-util.js +174 -0
  225. package/dist/util/socket-util.js.map +1 -0
  226. package/dist/util/tls.d.ts +68 -0
  227. package/dist/util/tls.d.ts.map +1 -0
  228. package/dist/util/tls.js +220 -0
  229. package/dist/util/tls.js.map +1 -0
  230. package/dist/util/type-utils.d.ts +14 -0
  231. package/dist/util/type-utils.d.ts.map +1 -0
  232. package/dist/util/type-utils.js +3 -0
  233. package/dist/util/type-utils.js.map +1 -0
  234. package/dist/util/url.d.ts +17 -0
  235. package/dist/util/url.d.ts.map +1 -0
  236. package/dist/util/url.js +96 -0
  237. package/dist/util/url.js.map +1 -0
  238. package/dist/util/util.d.ts +8 -0
  239. package/dist/util/util.d.ts.map +1 -0
  240. package/dist/util/util.js +41 -0
  241. package/dist/util/util.js.map +1 -0
  242. package/docs/api-docs-landing-page.md +11 -0
  243. package/docs/runkitExample.js +16 -0
  244. package/docs/setup.md +136 -0
  245. package/nfyb8qx5.cjs +1 -0
  246. package/package.json +194 -4
  247. package/src/admin/admin-bin.ts +62 -0
  248. package/src/admin/admin-plugin-types.ts +29 -0
  249. package/src/admin/admin-server.ts +619 -0
  250. package/src/admin/graphql-utils.ts +28 -0
  251. package/src/admin/mockttp-admin-model.ts +264 -0
  252. package/src/admin/mockttp-admin-plugin.ts +59 -0
  253. package/src/admin/mockttp-admin-server.ts +27 -0
  254. package/src/admin/mockttp-schema.ts +222 -0
  255. package/src/client/admin-client.ts +652 -0
  256. package/src/client/admin-query.ts +52 -0
  257. package/src/client/mocked-endpoint-client.ts +32 -0
  258. package/src/client/mockttp-admin-request-builder.ts +540 -0
  259. package/src/client/mockttp-client.ts +178 -0
  260. package/src/client/schema-introspection.ts +131 -0
  261. package/src/main.browser.ts +60 -0
  262. package/src/main.ts +160 -0
  263. package/src/mockttp.ts +926 -0
  264. package/src/pluggable-admin-api/mockttp-pluggable-admin.browser.ts +7 -0
  265. package/src/pluggable-admin-api/mockttp-pluggable-admin.ts +13 -0
  266. package/src/pluggable-admin-api/pluggable-admin.browser.ts +9 -0
  267. package/src/pluggable-admin-api/pluggable-admin.ts +36 -0
  268. package/src/rules/base-rule-builder.ts +312 -0
  269. package/src/rules/completion-checkers.ts +90 -0
  270. package/src/rules/http-agents.ts +119 -0
  271. package/src/rules/matchers.ts +665 -0
  272. package/src/rules/passthrough-handling-definitions.ts +111 -0
  273. package/src/rules/passthrough-handling.ts +376 -0
  274. package/src/rules/proxy-config.ts +136 -0
  275. package/src/rules/requests/request-handler-definitions.ts +1089 -0
  276. package/src/rules/requests/request-handlers.ts +1369 -0
  277. package/src/rules/requests/request-rule-builder.ts +481 -0
  278. package/src/rules/requests/request-rule.ts +148 -0
  279. package/src/rules/rule-deserialization.ts +55 -0
  280. package/src/rules/rule-parameters.ts +41 -0
  281. package/src/rules/rule-serialization.ts +29 -0
  282. package/src/rules/websockets/websocket-handler-definitions.ts +196 -0
  283. package/src/rules/websockets/websocket-handlers.ts +509 -0
  284. package/src/rules/websockets/websocket-rule-builder.ts +275 -0
  285. package/src/rules/websockets/websocket-rule.ts +136 -0
  286. package/src/serialization/body-serialization.ts +84 -0
  287. package/src/serialization/serialization.ts +373 -0
  288. package/src/server/http-combo-server.ts +424 -0
  289. package/src/server/mocked-endpoint.ts +44 -0
  290. package/src/server/mockttp-server.ts +1110 -0
  291. package/src/types.ts +433 -0
  292. package/src/util/buffer-utils.ts +164 -0
  293. package/src/util/dns.ts +52 -0
  294. package/src/util/error.ts +18 -0
  295. package/src/util/header-utils.ts +220 -0
  296. package/src/util/openssl-compat.ts +26 -0
  297. package/src/util/promise.ts +31 -0
  298. package/src/util/request-utils.ts +607 -0
  299. package/src/util/server-utils.ts +18 -0
  300. package/src/util/socket-util.ts +193 -0
  301. package/src/util/tls.ts +348 -0
  302. package/src/util/type-utils.ts +15 -0
  303. package/src/util/url.ts +113 -0
  304. package/src/util/util.ts +39 -0
@@ -0,0 +1,33 @@
1
+ import * as _ from 'lodash';
2
+ import * as tls from 'tls';
3
+ import { Headers } from '../types';
4
+ import { DnsLookupFunction } from '../util/dns';
5
+ import { CallbackRequestResult, CallbackResponseMessageResult } from './requests/request-handler-definitions';
6
+ import { CADefinition, PassThroughLookupOptions } from './passthrough-handling-definitions';
7
+ export declare const getUpstreamTlsOptions: (strictChecks: boolean) => tls.SecureContextOptions;
8
+ export declare function getTrustedCAs(trustedCAs: Array<string | CADefinition> | undefined, additionalTrustedCAs: Array<CADefinition> | undefined): Promise<Array<string> | undefined>;
9
+ /**
10
+ * Takes a callback result and some headers, and returns a ready to send body, using the headers
11
+ * (and potentially modifying them) to match the content type & encoding.
12
+ */
13
+ export declare function buildOverriddenBody(callbackResult: CallbackRequestResult | CallbackResponseMessageResult | void, headers: Headers): Promise<Uint8Array | Buffer | undefined>;
14
+ /**
15
+ * Autocorrect the host header only in the case that if you didn't explicitly
16
+ * override it yourself for some reason (e.g. if you're testing bad behaviour).
17
+ */
18
+ export declare function getHostAfterModification(reqUrl: string, originalHeaders: Headers, replacementHeaders: Headers | undefined): string;
19
+ export declare const OVERRIDABLE_REQUEST_PSEUDOHEADERS: readonly [":authority", ":scheme"];
20
+ /**
21
+ * Automatically update the :scheme and :authority headers to match the updated URL,
22
+ * as long as they weren't explicitly overriden themselves, in which case let them
23
+ * be set to any invalid value you like (e.g. to send a request to one server but
24
+ * pretend it was sent to another).
25
+ */
26
+ export declare function getH2HeadersAfterModification(reqUrl: string, originalHeaders: Headers, replacementHeaders: Headers | undefined): {
27
+ [K in typeof OVERRIDABLE_REQUEST_PSEUDOHEADERS[number]]: string;
28
+ };
29
+ export declare function getContentLengthAfterModification(body: string | Uint8Array | Buffer, originalHeaders: Headers, replacementHeaders: Headers | undefined, mismatchAllowed?: boolean): string | undefined;
30
+ export declare function shouldUseStrictHttps(hostname: string, port: number, ignoreHostHttpsErrors: string[] | boolean): boolean;
31
+ export declare const getDnsLookupFunction: ((lookupOptions: PassThroughLookupOptions | undefined) => DnsLookupFunction) & _.MemoizedFunction;
32
+ export declare function getClientRelativeHostname(hostname: string | null, remoteIp: string | undefined, lookupFn: DnsLookupFunction): Promise<string | null>;
33
+ //# sourceMappingURL=passthrough-handling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passthrough-handling.d.ts","sourceRoot":"","sources":["../../src/rules/passthrough-handling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAK3B,OAAO,EAAiB,OAAO,EAAE,MAAM,UAAU,CAAC;AAIlD,OAAO,EAAwB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAItE,OAAO,EACH,qBAAqB,EACrB,6BAA6B,EAChC,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACH,YAAY,EACZ,wBAAwB,EAC3B,MAAM,oCAAoC,CAAC;AAY5C,eAAO,MAAM,qBAAqB,iBAAkB,OAAO,KAAG,GAAG,CAAC,oBAiEhE,CAAC;AAEH,wBAAsB,aAAa,CAC/B,UAAU,EAAE,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,GAAG,SAAS,EACpD,oBAAoB,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,SAAS,GACtD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAapC;AAcD;;;GAGG;AACH,wBAAsB,mBAAmB,CACrC,cAAc,EAAE,qBAAqB,GAAG,6BAA6B,GAAG,IAAI,EAC5E,OAAO,EAAE,OAAO,4CA+BnB;AAsCD;;;GAGG;AACH,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,OAAO,EACxB,kBAAkB,EAAE,OAAO,GAAG,SAAS,GACxC,MAAM,CAOR;AAED,eAAO,MAAM,iCAAiC,oCAGpC,CAAC;AAEX;;;;;GAKG;AACH,wBAAgB,6BAA6B,CACzC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,OAAO,EACxB,kBAAkB,EAAE,OAAO,GAAG,SAAS,GACxC;KAAG,CAAC,IAAI,OAAO,iCAAiC,CAAC,MAAM,CAAC,GAAG,MAAM;CAAE,CAiBrE;AAGD,wBAAgB,iCAAiC,CAC7C,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,EAClC,eAAe,EAAE,OAAO,EACxB,kBAAkB,EAAE,OAAO,GAAG,SAAS,EACvC,eAAe,GAAE,OAAe,GACjC,MAAM,GAAG,SAAS,CAsCpB;AAID,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,MAAM,EAAE,GAAG,OAAO,WAe5C;AAED,eAAO,MAAM,oBAAoB,mBAA6B,wBAAwB,GAAG,SAAS,4CAoBhG,CAAC;AAEH,wBAAsB,yBAAyB,CAC3C,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,QAAQ,EAAE,iBAAiB,0BAyB9B"}
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDnsLookupFunction = exports.OVERRIDABLE_REQUEST_PSEUDOHEADERS = exports.getUpstreamTlsOptions = void 0;
4
+ exports.getTrustedCAs = getTrustedCAs;
5
+ exports.buildOverriddenBody = buildOverriddenBody;
6
+ exports.getHostAfterModification = getHostAfterModification;
7
+ exports.getH2HeadersAfterModification = getH2HeadersAfterModification;
8
+ exports.getContentLengthAfterModification = getContentLengthAfterModification;
9
+ exports.shouldUseStrictHttps = shouldUseStrictHttps;
10
+ exports.getClientRelativeHostname = getClientRelativeHostname;
11
+ const _ = require("lodash");
12
+ const fs = require("fs/promises");
13
+ const tls = require("tls");
14
+ const url = require("url");
15
+ const common_tags_1 = require("common-tags");
16
+ const cacheable_lookup_1 = require("cacheable-lookup");
17
+ const util_1 = require("../util/util");
18
+ const buffer_utils_1 = require("../util/buffer-utils");
19
+ const socket_util_1 = require("../util/socket-util");
20
+ const dns_1 = require("../util/dns");
21
+ const request_utils_1 = require("../util/request-utils");
22
+ const openssl_compat_1 = require("../util/openssl-compat");
23
+ // TLS settings for proxied connections, intended to avoid TLS fingerprint blocking
24
+ // issues so far as possible, by closely emulating a Firefox Client Hello:
25
+ const NEW_CURVES_SUPPORTED = (0, openssl_compat_1.areFFDHECurvesSupported)(process.versions.openssl);
26
+ const SSL_OP_LEGACY_SERVER_CONNECT = 1 << 2;
27
+ const SSL_OP_TLSEXT_PADDING = 1 << 4;
28
+ const SSL_OP_NO_ENCRYPT_THEN_MAC = 1 << 19;
29
+ // All settings are designed to exactly match Firefox v103, since that's a good baseline
30
+ // that seems to be widely accepted and is easy to emulate from Node.js.
31
+ const getUpstreamTlsOptions = (strictChecks) => ({
32
+ ecdhCurve: [
33
+ 'X25519',
34
+ 'prime256v1', // N.B. Equivalent to secp256r1
35
+ 'secp384r1',
36
+ 'secp521r1',
37
+ ...(NEW_CURVES_SUPPORTED
38
+ ? [
39
+ 'ffdhe2048',
40
+ 'ffdhe3072'
41
+ ] : [])
42
+ ].join(':'),
43
+ sigalgs: [
44
+ 'ecdsa_secp256r1_sha256',
45
+ 'ecdsa_secp384r1_sha384',
46
+ 'ecdsa_secp521r1_sha512',
47
+ 'rsa_pss_rsae_sha256',
48
+ 'rsa_pss_rsae_sha384',
49
+ 'rsa_pss_rsae_sha512',
50
+ 'rsa_pkcs1_sha256',
51
+ 'rsa_pkcs1_sha384',
52
+ 'rsa_pkcs1_sha512',
53
+ 'ECDSA+SHA1',
54
+ 'rsa_pkcs1_sha1'
55
+ ].join(':'),
56
+ ciphers: [
57
+ 'TLS_AES_128_GCM_SHA256',
58
+ 'TLS_CHACHA20_POLY1305_SHA256',
59
+ 'TLS_AES_256_GCM_SHA384',
60
+ 'ECDHE-ECDSA-AES128-GCM-SHA256',
61
+ 'ECDHE-RSA-AES128-GCM-SHA256',
62
+ 'ECDHE-ECDSA-CHACHA20-POLY1305',
63
+ 'ECDHE-RSA-CHACHA20-POLY1305',
64
+ 'ECDHE-ECDSA-AES256-GCM-SHA384',
65
+ 'ECDHE-RSA-AES256-GCM-SHA384',
66
+ 'ECDHE-ECDSA-AES256-SHA',
67
+ 'ECDHE-ECDSA-AES128-SHA',
68
+ 'ECDHE-RSA-AES128-SHA',
69
+ 'ECDHE-RSA-AES256-SHA',
70
+ 'AES128-GCM-SHA256',
71
+ 'AES256-GCM-SHA384',
72
+ 'AES128-SHA',
73
+ 'AES256-SHA',
74
+ // This magic cipher is the very obtuse way that OpenSSL downgrades the overall
75
+ // security level to allow various legacy settings, protocols & ciphers:
76
+ ...(!strictChecks
77
+ ? ['@SECLEVEL=0']
78
+ : [])
79
+ ].join(':'),
80
+ secureOptions: strictChecks
81
+ ? SSL_OP_TLSEXT_PADDING | SSL_OP_NO_ENCRYPT_THEN_MAC
82
+ : SSL_OP_TLSEXT_PADDING | SSL_OP_NO_ENCRYPT_THEN_MAC | SSL_OP_LEGACY_SERVER_CONNECT,
83
+ ...{
84
+ // Valid, but not included in Node.js TLS module types:
85
+ requestOSCP: true
86
+ },
87
+ // Allow TLSv1, if !strict:
88
+ minVersion: strictChecks ? tls.DEFAULT_MIN_VERSION : 'TLSv1',
89
+ // Skip certificate validation entirely, if not strict:
90
+ rejectUnauthorized: strictChecks,
91
+ });
92
+ exports.getUpstreamTlsOptions = getUpstreamTlsOptions;
93
+ async function getTrustedCAs(trustedCAs, additionalTrustedCAs) {
94
+ if (trustedCAs && additionalTrustedCAs?.length) {
95
+ throw new Error(`trustedCAs and additionalTrustedCAs options are mutually exclusive`);
96
+ }
97
+ if (trustedCAs) {
98
+ return Promise.all(trustedCAs.map((caDefinition) => getCA(caDefinition)));
99
+ }
100
+ if (additionalTrustedCAs) {
101
+ const CAs = await Promise.all(additionalTrustedCAs.map((caDefinition) => getCA(caDefinition)));
102
+ return tls.rootCertificates.concat(CAs);
103
+ }
104
+ }
105
+ const getCA = async (caDefinition) => {
106
+ return typeof caDefinition === 'string'
107
+ ? caDefinition
108
+ : 'certPath' in caDefinition
109
+ ? await fs.readFile(caDefinition.certPath, 'utf8')
110
+ // 'cert' in caDefinition
111
+ : caDefinition.cert.toString('utf8');
112
+ };
113
+ // --- Various helpers for deriving parts of request/response data given partial overrides: ---
114
+ /**
115
+ * Takes a callback result and some headers, and returns a ready to send body, using the headers
116
+ * (and potentially modifying them) to match the content type & encoding.
117
+ */
118
+ async function buildOverriddenBody(callbackResult, headers) {
119
+ // Raw bodies are easy: use them as is.
120
+ if (callbackResult?.rawBody)
121
+ return callbackResult?.rawBody;
122
+ // In the json/body case, we need to get the body and transform it into a buffer
123
+ // for consistent handling later, and encode it to match the headers.
124
+ let replacementBody;
125
+ if (callbackResult?.json) {
126
+ headers['content-type'] = 'application/json';
127
+ replacementBody = JSON.stringify(callbackResult?.json);
128
+ }
129
+ else {
130
+ replacementBody = callbackResult?.body;
131
+ }
132
+ if (replacementBody === undefined)
133
+ return replacementBody;
134
+ let rawBuffer;
135
+ if ((0, request_utils_1.isMockttpBody)(replacementBody)) {
136
+ // It's our own bodyReader instance. That's not supposed to happen, but
137
+ // it's ok, we just need to use the buffer data instead of the whole object
138
+ rawBuffer = Buffer.from(replacementBody.buffer);
139
+ }
140
+ else if (replacementBody === '') {
141
+ // For empty bodies, it's slightly more convenient if they're truthy
142
+ rawBuffer = Buffer.alloc(0);
143
+ }
144
+ else {
145
+ rawBuffer = (0, buffer_utils_1.asBuffer)(replacementBody);
146
+ }
147
+ return await (0, request_utils_1.encodeBodyBuffer)(rawBuffer, headers);
148
+ }
149
+ /**
150
+ * If you override some headers, they have implications for the effective URL we send the
151
+ * request to. If you override that and the URL at the same time, it gets complicated.
152
+ *
153
+ * This method calculates the correct header value we should use: prioritising the header
154
+ * value you provide, printing a warning if it's contradictory, or return the URL-inferred
155
+ * value to override the header correctly if you didn't specify.
156
+ */
157
+ function deriveUrlLinkedHeader(originalHeaders, replacementHeaders, headerName, expectedValue // The inferred 'correct' value from the URL
158
+ ) {
159
+ const replacementValue = replacementHeaders?.[headerName];
160
+ if (replacementValue !== undefined) {
161
+ if (replacementValue !== expectedValue && replacementValue === originalHeaders[headerName]) {
162
+ // If you rewrite the URL-based header wrongly, by explicitly setting it to the
163
+ // existing value, we accept it but print a warning. This would be easy to
164
+ // do if you mutate the existing headers, for example, and ignore the host.
165
+ console.warn((0, common_tags_1.oneLine) `
166
+ Passthrough callback overrode the URL and the ${headerName} header
167
+ with mismatched values, which may be a mistake. The URL implies
168
+ ${expectedValue}, whilst the header was set to ${replacementValue}.
169
+ `);
170
+ }
171
+ // Whatever happens, if you explicitly set a value, we use it.
172
+ return replacementValue;
173
+ }
174
+ // If you didn't override the header at all, then we automatically ensure
175
+ // the correct value is set automatically.
176
+ return expectedValue;
177
+ }
178
+ /**
179
+ * Autocorrect the host header only in the case that if you didn't explicitly
180
+ * override it yourself for some reason (e.g. if you're testing bad behaviour).
181
+ */
182
+ function getHostAfterModification(reqUrl, originalHeaders, replacementHeaders) {
183
+ return deriveUrlLinkedHeader(originalHeaders, replacementHeaders, 'host', url.parse(reqUrl).host);
184
+ }
185
+ exports.OVERRIDABLE_REQUEST_PSEUDOHEADERS = [
186
+ ':authority',
187
+ ':scheme'
188
+ ];
189
+ /**
190
+ * Automatically update the :scheme and :authority headers to match the updated URL,
191
+ * as long as they weren't explicitly overriden themselves, in which case let them
192
+ * be set to any invalid value you like (e.g. to send a request to one server but
193
+ * pretend it was sent to another).
194
+ */
195
+ function getH2HeadersAfterModification(reqUrl, originalHeaders, replacementHeaders) {
196
+ const parsedUrl = url.parse(reqUrl);
197
+ return {
198
+ ':scheme': deriveUrlLinkedHeader(originalHeaders, replacementHeaders, ':scheme', parsedUrl.protocol.slice(0, -1)),
199
+ ':authority': deriveUrlLinkedHeader(originalHeaders, replacementHeaders, ':authority', parsedUrl.host)
200
+ };
201
+ }
202
+ // Helper to handle content-length nicely for you when rewriting requests with callbacks
203
+ function getContentLengthAfterModification(body, originalHeaders, replacementHeaders, mismatchAllowed = false) {
204
+ // If there was a content-length header, it might now be wrong, and it's annoying
205
+ // to need to set your own content-length override when you just want to change
206
+ // the body. To help out, if you override the body but don't explicitly override
207
+ // the (now invalid) content-length, then we fix it for you.
208
+ if (!_.has(originalHeaders, 'content-length')) {
209
+ // Nothing to override - use the replacement value, or undefined
210
+ return (replacementHeaders || {})['content-length'];
211
+ }
212
+ if (!replacementHeaders) {
213
+ // There was a length set, and you've provided a body but not changed it.
214
+ // You probably just want to send this body and have it work correctly,
215
+ // so we should fix the content length for you automatically.
216
+ return (0, util_1.byteLength)(body).toString();
217
+ }
218
+ // There was a content length before, and you're replacing the headers entirely
219
+ const lengthOverride = replacementHeaders['content-length']?.toString();
220
+ // If you're setting the content-length to the same as the origin headers, even
221
+ // though that's the wrong value, it *might* be that you're just extending the
222
+ // existing headers, and you're doing this by accident (we can't tell for sure).
223
+ // We use invalid content-length as instructed, but print a warning just in case.
224
+ if (lengthOverride === originalHeaders['content-length'] &&
225
+ lengthOverride !== (0, util_1.byteLength)(body).toString() &&
226
+ !mismatchAllowed // Set for HEAD responses
227
+ ) {
228
+ console.warn((0, common_tags_1.oneLine) `
229
+ Passthrough modifications overrode the body and the content-length header
230
+ with mismatched values, which may be a mistake. The body contains
231
+ ${(0, util_1.byteLength)(body)} bytes, whilst the header was set to ${lengthOverride}.
232
+ `);
233
+ }
234
+ return lengthOverride;
235
+ }
236
+ // Function to check if we should skip https errors for the current hostname and port,
237
+ // based on the given config
238
+ function shouldUseStrictHttps(hostname, port, ignoreHostHttpsErrors) {
239
+ let skipHttpsErrors = false;
240
+ if (ignoreHostHttpsErrors === true) {
241
+ // Ignore cert errors if `ignoreHostHttpsErrors` is set to true, or
242
+ skipHttpsErrors = true;
243
+ }
244
+ else if (Array.isArray(ignoreHostHttpsErrors) && (
245
+ // if the whole hostname or host+port is whitelisted
246
+ _.includes(ignoreHostHttpsErrors, hostname) ||
247
+ _.includes(ignoreHostHttpsErrors, `${hostname}:${port}`))) {
248
+ skipHttpsErrors = true;
249
+ }
250
+ return !skipHttpsErrors;
251
+ }
252
+ exports.getDnsLookupFunction = _.memoize((lookupOptions) => {
253
+ if (!lookupOptions) {
254
+ // By default, use 10s caching of hostnames, just to reduce the delay from
255
+ // endlessly 10ms query delay for 'localhost' with every request.
256
+ return new dns_1.CachedDns(10000).lookup;
257
+ }
258
+ else {
259
+ // Or if options are provided, use those to configure advanced DNS cases:
260
+ const cacheableLookup = new cacheable_lookup_1.default({
261
+ maxTtl: lookupOptions.maxTtl,
262
+ errorTtl: lookupOptions.errorTtl,
263
+ // As little caching of "use the fallback server" as possible:
264
+ fallbackDuration: 0
265
+ });
266
+ if (lookupOptions.servers) {
267
+ cacheableLookup.servers = lookupOptions.servers;
268
+ }
269
+ return cacheableLookup.lookup;
270
+ }
271
+ });
272
+ async function getClientRelativeHostname(hostname, remoteIp, lookupFn) {
273
+ if (!hostname || !remoteIp || (0, socket_util_1.isLocalhostAddress)(remoteIp))
274
+ return hostname;
275
+ // Otherwise, we have a request from a different machine (or Docker container/VM/etc) and we need
276
+ // to make sure that 'localhost' means _that_ machine, not ourselves.
277
+ // This check must be run before req modifications. If a modification changes the address to localhost,
278
+ // then presumably it really does mean *this* localhost.
279
+ if (
280
+ // If the hostname is a known localhost address, we're done:
281
+ (0, socket_util_1.isLocalhostAddress)(hostname) ||
282
+ // Otherwise, we look up the IP, so we can accurately check for localhost-bound requests. This adds a little
283
+ // delay, but since it's cached we save the equivalent delay in request lookup later, so it should be
284
+ // effectively free. We ignore errors to delegate unresolvable etc to request processing later.
285
+ (0, socket_util_1.isLocalhostAddress)(await (0, dns_1.dnsLookup)(lookupFn, hostname).catch(() => null))) {
286
+ return remoteIp;
287
+ // Note that we just redirect - we don't update the host header. From the POV of the target, it's still
288
+ // 'localhost' traffic that should appear identical to normal.
289
+ }
290
+ else {
291
+ return hostname;
292
+ }
293
+ }
294
+ //# sourceMappingURL=passthrough-handling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"passthrough-handling.js","sourceRoot":"","sources":["../../src/rules/passthrough-handling.ts"],"names":[],"mappings":";;;AAqGA,sCAgBC;AAkBD,kDAiCC;AA0CD,4DAWC;AAaD,sEAqBC;AAGD,8EA2CC;AAID,oDAkBC;AAwBD,8DA4BC;AAvXD,4BAA4B;AAC5B,kCAAkC;AAClC,2BAA2B;AAC3B,2BAA4B;AAC5B,6CAAsC;AACtC,uDAA+C;AAG/C,uCAA0C;AAC1C,uDAAgD;AAChD,qDAAyD;AACzD,qCAAsE;AACtE,yDAAwE;AACxE,2DAAiE;AAWjE,mFAAmF;AACnF,0EAA0E;AAC1E,MAAM,oBAAoB,GAAG,IAAA,wCAAuB,EAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAE/E,MAAM,4BAA4B,GAAG,CAAC,IAAI,CAAC,CAAC;AAC5C,MAAM,qBAAqB,GAAG,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,0BAA0B,GAAG,CAAC,IAAI,EAAE,CAAC;AAE3C,wFAAwF;AACxF,wEAAwE;AACjE,MAAM,qBAAqB,GAAG,CAAC,YAAqB,EAA4B,EAAE,CAAC,CAAC;IACvF,SAAS,EAAE;QACP,QAAQ;QACR,YAAY,EAAE,+BAA+B;QAC7C,WAAW;QACX,WAAW;QACX,GAAG,CAAC,oBAAoB;YACpB,CAAC,CAAC;gBACE,WAAW;gBACX,WAAW;aACd,CAAC,CAAC,CAAC,EAAE,CACT;KACJ,CAAC,IAAI,CAAC,GAAG,CAAC;IACX,OAAO,EAAE;QACL,wBAAwB;QACxB,w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AC;SACtB,CAAC,CAAC;QAEH,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;YACxB,eAAe,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;QACpD,CAAC;QAED,OAAO,eAAe,CAAC,MAAM,CAAC;IAClC,CAAC;AACL,CAAC,CAAC,CAAC;AAEI,KAAK,UAAU,yBAAyB,CAC3C,QAAuB,EACvB,QAA4B,EAC5B,QAA2B;IAE3B,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,IAAI,IAAA,gCAAkB,EAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAE5E,iGAAiG;IACjG,qEAAqE;IAErE,uGAAuG;IACvG,wDAAwD;IAExD;IACI,4DAA4D;IAC5D,IAAA,gCAAkB,EAAC,QAAQ,CAAC;QAC5B,4GAA4G;QAC5G,qGAAqG;QACrG,+FAA+F;QAC/F,IAAA,gCAAkB,EAAC,MAAM,IAAA,eAAS,EAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,EAC3E,CAAC;QACC,OAAO,QAAQ,CAAC;QAEhB,uGAAuG;QACvG,8DAA8D;IAClE,CAAC;SAAM,CAAC;QACJ,OAAO,QAAQ,CAAC;IACpB,CAAC;AACL,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { MaybePromise } from '../util/type-utils';
2
+ import { RuleParameterReference } from './rule-parameters';
3
+ import { CADefinition } from './passthrough-handling-definitions';
4
+ /**
5
+ * A ProxySetting is a specific proxy setting to use, which is passed to a proxy agent
6
+ * who will manage creating a socket for the request (directly, or tunnelled, or whatever).
7
+ */
8
+ export interface ProxySetting {
9
+ /**
10
+ * The URL for the proxy to forward traffic through.
11
+ *
12
+ * This can be any URL supported by https://www.npmjs.com/package/proxy-agent.
13
+ * For example: http://..., socks5://..., pac+http://...
14
+ */
15
+ proxyUrl: string;
16
+ /**
17
+ * A list of no-proxy values, matching hosts' traffic should *not* be proxied.
18
+ *
19
+ * This is a common proxy feature, but unfortunately isn't standardized. See
20
+ * https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/ for some
21
+ * background. This implementation is intended to match Curl's behaviour, and
22
+ * any differences are a bug.
23
+ *
24
+ * The currently supported formats are:
25
+ * - example.com (matches domain and all subdomains)
26
+ * - example.com:443 (matches domain and all subdomains, but only on that port)
27
+ * - 10.0.0.1 (matches IP, but only when used directly - does not resolve domains)
28
+ *
29
+ * Some other formats (e.g. leading dots or *.) will work, but the leading
30
+ * characters are ignored. More formats may be added in future, e.g. CIDR ranges.
31
+ * To maximize compatibility with values used elsewhere, unrecognized formats
32
+ * will generally be ignored, but may match in unexpected ways.
33
+ */
34
+ noProxy?: string[];
35
+ /**
36
+ * CAs to trust for HTTPS connections to the proxy. Ignored if the connection to
37
+ * the proxy is not HTTPS. If not specified, this will default to the Node
38
+ * defaults, or you can override them here completely.
39
+ *
40
+ * This sets the complete list of trusted CAs, and is mutually exclusive with the
41
+ * `additionalTrustedCAs` option, which adds additional CAs (but also trusts the
42
+ * Node default CAs too).
43
+ *
44
+ * This should be specified as either a { cert: string | Buffer } object or a
45
+ * { certPath: string } object (to read the cert from disk). The previous
46
+ * simple string format is supported but deprecated.
47
+ */
48
+ trustedCAs?: Array<string | CADefinition>;
49
+ /**
50
+ * Extra CAs to trust for HTTPS connections to the proxy. Ignored if the connection
51
+ * to the proxy is not HTTPS.
52
+ *
53
+ * This appends to the list of trusted CAs, and is mutually exclusive with the
54
+ * `trustedCAs` option, which completely overrides the list of CAs.
55
+ */
56
+ additionalTrustedCAs?: Array<CADefinition>;
57
+ }
58
+ /**
59
+ * A ProxySettingSource is a way to calculate the ProxySetting for a given request. It
60
+ * may be a fixed ProxySetting value, or a callback to get ProxySetting values, or an
61
+ * array of sources, which should be iterated to get the first usable value
62
+ */
63
+ export type ProxySettingSource = ProxySetting | ProxySettingCallback | Array<ProxySettingSource> | undefined;
64
+ export type ProxySettingCallbackParams = {
65
+ hostname: string;
66
+ };
67
+ export type ProxySettingCallback = (params: ProxySettingCallbackParams) => MaybePromise<ProxySetting | undefined>;
68
+ /**
69
+ * A ProxyConfig is externally provided config that specifies a ProxySettingSource.
70
+ * It might be a ProxySettingSource itself, or it might include references to rule
71
+ * parameters, which must be dereferenced to make it usable as a ProxySettingSource.
72
+ */
73
+ export type ProxyConfig = ProxySettingSource | RuleParameterReference<ProxySettingSource> | Array<ProxySettingSource | RuleParameterReference<ProxySettingSource>>;
74
+ export declare function getProxySetting(configSource: ProxySettingSource, params: ProxySettingCallbackParams): Promise<ProxySetting | undefined>;
75
+ export declare const matchesNoProxy: (hostname: string, portNum: number, noProxyValues: string[] | undefined) => boolean;
76
+ //# sourceMappingURL=proxy-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-config.d.ts","sourceRoot":"","sources":["../../src/rules/proxy-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,EAAE,KAAK,CACZ,MAAM,GACN,YAAY,CACjB,CAAC;IAEF;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GACxB,YAAY,GACZ,oBAAoB,GACpB,KAAK,CAAC,kBAAkB,CAAC,GACzB,SAAS,CAAC;AAEhB,MAAM,MAAM,0BAA0B,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAC9D,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,0BAA0B,KAAK,YAAY,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;AAElH;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACpB,kBAAkB,GAClB,sBAAsB,CAAC,kBAAkB,CAAC,GAC1C,KAAK,CAAC,kBAAkB,GAAG,sBAAsB,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAE1E,wBAAsB,eAAe,CACjC,YAAY,EAAE,kBAAkB,EAChC,MAAM,EAAE,0BAA0B,qCAYrC;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,WAAW,MAAM,iBAAiB,MAAM,EAAE,GAAG,SAAS,YA4BpG,CAAA"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchesNoProxy = void 0;
4
+ exports.getProxySetting = getProxySetting;
5
+ const _ = require("lodash");
6
+ async function getProxySetting(configSource, params) {
7
+ if (_.isFunction(configSource))
8
+ return configSource(params);
9
+ else if (_.isArray(configSource)) {
10
+ let result;
11
+ for (let configArrayOption of configSource) {
12
+ result = await getProxySetting(configArrayOption, params);
13
+ if (result)
14
+ break;
15
+ }
16
+ return result;
17
+ }
18
+ else
19
+ return configSource;
20
+ }
21
+ const matchesNoProxy = (hostname, portNum, noProxyValues) => {
22
+ if (!noProxyValues || noProxyValues.length === 0)
23
+ return false; // Skip everything in the common case.
24
+ const port = portNum.toString();
25
+ const hostParts = hostname.split('.').reverse();
26
+ return noProxyValues.some((noProxy) => {
27
+ const [noProxyHost, noProxyPort] = noProxy.split(':');
28
+ let noProxyParts = noProxyHost.split('.').reverse();
29
+ const lastPart = noProxyParts[noProxyParts.length - 1];
30
+ if (lastPart === '' || lastPart === '*') {
31
+ noProxyParts = noProxyParts.slice(0, -1);
32
+ }
33
+ if (noProxyPort && port !== noProxyPort)
34
+ return false;
35
+ for (let i = 0; i < noProxyParts.length; i++) {
36
+ let noProxyPart = noProxyParts[i];
37
+ let hostPart = hostParts[i];
38
+ if (hostPart === undefined)
39
+ return false; // No-proxy is longer than hostname
40
+ if (noProxyPart !== hostPart)
41
+ return false; // Mismatch
42
+ }
43
+ // If we run out of no-proxy parts with no mismatch then we've matched
44
+ return true;
45
+ });
46
+ };
47
+ exports.matchesNoProxy = matchesNoProxy;
48
+ //# sourceMappingURL=proxy-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy-config.js","sourceRoot":"","sources":["../../src/rules/proxy-config.ts"],"names":[],"mappings":";;;AA2FA,0CAcC;AAzGD,4BAA4B;AA2FrB,KAAK,UAAU,eAAe,CACjC,YAAgC,EAChC,MAAkC;IAElC,IAAI,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;SACvD,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAC/B,IAAI,MAAgC,CAAC;QACrC,KAAK,IAAI,iBAAiB,IAAI,YAAY,EAAE,CAAC;YACzC,MAAM,GAAG,MAAM,eAAe,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;YAC1D,IAAI,MAAM;gBAAE,MAAM;QACtB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;;QACI,OAAO,YAAY,CAAC;AAC7B,CAAC;AAEM,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,OAAe,EAAE,aAAmC,EAAE,EAAE;IACrG,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,sCAAsC;IAEtG,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAEhD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAClC,MAA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