1+ import type * as Mockttp from 'mockttp' ;
2+
3+ // --- Request definition types ---
4+
5+ export type RawHeaders = Mockttp . RawHeaders ;
6+
7+ export interface RequestDefinition {
8+ method : string ;
9+ url : string ;
10+
11+ /**
12+ * The raw headers to send. These will be sent exactly as provided - no headers
13+ * will be added automatically.
14+ *
15+ * Note that this means omitting the 'Host' header may cause problems, as will
16+ * omitting both 'Content-Length' and 'Transfer-Encoding' on requests with
17+ * bodies.
18+ */
19+ headers : RawHeaders ;
20+
21+ rawBody ?: Uint8Array ;
22+ }
23+
24+ // --- Request option types ---
25+
26+ export const RULE_PARAM_REF_KEY = '__rule_param_reference__' ;
27+ type ClientProxyRuleParamReference = { [ RULE_PARAM_REF_KEY ] : string } ;
28+
29+ export type ClientProxyConfig =
30+ | undefined // No Docker, no user or system proxy
31+ | Mockttp . ProxySetting // User or system proxy
32+ | ClientProxyRuleParamReference // Docker proxy (must be dereferenced)
33+ | Array < Mockttp . ProxySetting | ClientProxyRuleParamReference > // Both, ordered
34+
35+ export interface RequestOptions {
36+ /**
37+ * A list of hostnames for which server certificate and TLS version errors
38+ * should be ignored (none, by default).
39+ *
40+ * If set to 'true', HTTPS errors will be ignored for all hosts. WARNING:
41+ * Use this at your own risk. Setting this to `true` can open your
42+ * application to MITM attacks and should never be used over any network
43+ * that is not completed trusted end-to-end.
44+ */
45+ ignoreHostHttpsErrors ?: string [ ] | boolean ;
46+
47+ /**
48+ * An array of additional certificates, which should be trusted as certificate
49+ * authorities for upstream hosts, in addition to Node.js's built-in certificate
50+ * authorities.
51+ *
52+ * Each certificate should be an object with a `cert` key containing the PEM
53+ * certificate as a string.
54+ */
55+ trustAdditionalCAs ?: Array < { cert : string } > ;
56+
57+ /**
58+ * A client certificate that should be used for the connection, if the server
59+ * requests one during the TLS handshake.
60+ */
61+ clientCertificate ?: { pfx : Buffer , passphrase ?: string } ;
62+
63+ /**
64+ * Proxy configuration, specifying how (if at all) a proxy that should be used
65+ * for upstream connections.
66+ */
67+ proxyConfig ?: ClientProxyConfig ;
68+
69+ /**
70+ * Custom DNS options, to allow configuration of the resolver used when
71+ * forwarding requests upstream. Passing any option switches from using node's
72+ * default dns.lookup function to using the cacheable-lookup module, which
73+ * will cache responses.
74+ */
75+ lookupOptions ?: { servers ?: string [ ] } ;
76+
77+ /**
78+ * An abort signal, which can be used to cancel the in-process request if
79+ * required.
80+ */
81+ abortSignal ?: AbortSignal ;
82+ }
83+
84+ // --- Response types ---
85+
86+ export type ResponseStreamEvents =
87+ | RequestStart
88+ | ResponseHead
89+ | ResponseBodyPart
90+ | ResponseEnd ;
91+ // Other notable event is errors (via 'error' event)
92+
93+ export interface RequestStart {
94+ type : 'request-start' ;
95+ startTime : number ; // Unix timestamp
96+ timestamp : number ; // High precision timer (for relative calculations on later events)
97+ }
98+
99+ export interface ResponseHead {
100+ type : 'response-head' ;
101+ statusCode : number ;
102+ statusMessage ?: string ;
103+ headers : RawHeaders ;
104+ timestamp : number ;
105+ }
106+
107+ export interface ResponseBodyPart {
108+ type : 'response-body-part' ;
109+ rawBody : Buffer ;
110+ timestamp : number ;
111+ }
112+
113+ export interface ResponseEnd {
114+ type : 'response-end' ;
115+ timestamp : number ;
116+ }
0 commit comments