m06_task3.js 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. package/.idea/.name +1 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +10 -0
  3. package/.idea/jsLibraryMappings.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/node_lab_6.iml +12 -0
  6. package/06_task2.html +73 -0
  7. package/06_task2.js +52 -0
  8. package/06_task3.js +3 -0
  9. package/06_task4.js +3 -0
  10. package/m06_task3.js +28 -0
  11. package/package/index.js +28 -0
  12. package/package/node_modules/.package-lock.json +31 -0
  13. package/package/node_modules/@types/node/LICENSE +21 -0
  14. package/package/node_modules/@types/node/README.md +16 -0
  15. package/package/node_modules/@types/node/assert/strict.d.ts +8 -0
  16. package/package/node_modules/@types/node/assert.d.ts +961 -0
  17. package/package/node_modules/@types/node/async_hooks.d.ts +501 -0
  18. package/package/node_modules/@types/node/buffer.d.ts +2258 -0
  19. package/package/node_modules/@types/node/child_process.d.ts +1369 -0
  20. package/package/node_modules/@types/node/cluster.d.ts +410 -0
  21. package/package/node_modules/@types/node/console.d.ts +412 -0
  22. package/package/node_modules/@types/node/constants.d.ts +18 -0
  23. package/package/node_modules/@types/node/crypto.d.ts +3964 -0
  24. package/package/node_modules/@types/node/dgram.d.ts +545 -0
  25. package/package/node_modules/@types/node/diagnostics_channel.d.ts +153 -0
  26. package/package/node_modules/@types/node/dns/promises.d.ts +370 -0
  27. package/package/node_modules/@types/node/dns.d.ts +659 -0
  28. package/package/node_modules/@types/node/dom-events.d.ts +126 -0
  29. package/package/node_modules/@types/node/domain.d.ts +170 -0
  30. package/package/node_modules/@types/node/events.d.ts +678 -0
  31. package/package/node_modules/@types/node/fs/promises.d.ts +1138 -0
  32. package/package/node_modules/@types/node/fs.d.ts +3872 -0
  33. package/package/node_modules/@types/node/globals.d.ts +300 -0
  34. package/package/node_modules/@types/node/globals.global.d.ts +1 -0
  35. package/package/node_modules/@types/node/http.d.ts +1614 -0
  36. package/package/node_modules/@types/node/http2.d.ts +2134 -0
  37. package/package/node_modules/@types/node/https.d.ts +541 -0
  38. package/package/node_modules/@types/node/index.d.ts +133 -0
  39. package/package/node_modules/@types/node/inspector.d.ts +2741 -0
  40. package/package/node_modules/@types/node/module.d.ts +114 -0
  41. package/package/node_modules/@types/node/net.d.ts +869 -0
  42. package/package/node_modules/@types/node/os.d.ts +466 -0
  43. package/package/node_modules/@types/node/package.json +232 -0
  44. package/package/node_modules/@types/node/path.d.ts +191 -0
  45. package/package/node_modules/@types/node/perf_hooks.d.ts +625 -0
  46. package/package/node_modules/@types/node/process.d.ts +1482 -0
  47. package/package/node_modules/@types/node/punycode.d.ts +117 -0
  48. package/package/node_modules/@types/node/querystring.d.ts +131 -0
  49. package/package/node_modules/@types/node/readline/promises.d.ts +143 -0
  50. package/package/node_modules/@types/node/readline.d.ts +653 -0
  51. package/package/node_modules/@types/node/repl.d.ts +424 -0
  52. package/package/node_modules/@types/node/stream/consumers.d.ts +12 -0
  53. package/package/node_modules/@types/node/stream/promises.d.ts +42 -0
  54. package/package/node_modules/@types/node/stream/web.d.ts +330 -0
  55. package/package/node_modules/@types/node/stream.d.ts +1340 -0
  56. package/package/node_modules/@types/node/string_decoder.d.ts +67 -0
  57. package/package/node_modules/@types/node/test.d.ts +314 -0
  58. package/package/node_modules/@types/node/timers/promises.d.ts +68 -0
  59. package/package/node_modules/@types/node/timers.d.ts +94 -0
  60. package/package/node_modules/@types/node/tls.d.ts +1028 -0
  61. package/package/node_modules/@types/node/trace_events.d.ts +171 -0
  62. package/package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  63. package/package/node_modules/@types/node/ts4.8/assert.d.ts +961 -0
  64. package/package/node_modules/@types/node/ts4.8/async_hooks.d.ts +501 -0
  65. package/package/node_modules/@types/node/ts4.8/buffer.d.ts +2259 -0
  66. package/package/node_modules/@types/node/ts4.8/child_process.d.ts +1369 -0
  67. package/package/node_modules/@types/node/ts4.8/cluster.d.ts +410 -0
  68. package/package/node_modules/@types/node/ts4.8/console.d.ts +412 -0
  69. package/package/node_modules/@types/node/ts4.8/constants.d.ts +18 -0
  70. package/package/node_modules/@types/node/ts4.8/crypto.d.ts +3964 -0
  71. package/package/node_modules/@types/node/ts4.8/dgram.d.ts +545 -0
  72. package/package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +153 -0
  73. package/package/node_modules/@types/node/ts4.8/dns/promises.d.ts +370 -0
  74. package/package/node_modules/@types/node/ts4.8/dns.d.ts +659 -0
  75. package/package/node_modules/@types/node/ts4.8/dom-events.d.ts +126 -0
  76. package/package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  77. package/package/node_modules/@types/node/ts4.8/events.d.ts +678 -0
  78. package/package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1138 -0
  79. package/package/node_modules/@types/node/ts4.8/fs.d.ts +3872 -0
  80. package/package/node_modules/@types/node/ts4.8/globals.d.ts +294 -0
  81. package/package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  82. package/package/node_modules/@types/node/ts4.8/http.d.ts +1614 -0
  83. package/package/node_modules/@types/node/ts4.8/http2.d.ts +2134 -0
  84. package/package/node_modules/@types/node/ts4.8/https.d.ts +541 -0
  85. package/package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  86. package/package/node_modules/@types/node/ts4.8/inspector.d.ts +2741 -0
  87. package/package/node_modules/@types/node/ts4.8/module.d.ts +114 -0
  88. package/package/node_modules/@types/node/ts4.8/net.d.ts +869 -0
  89. package/package/node_modules/@types/node/ts4.8/os.d.ts +466 -0
  90. package/package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  91. package/package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +625 -0
  92. package/package/node_modules/@types/node/ts4.8/process.d.ts +1482 -0
  93. package/package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  94. package/package/node_modules/@types/node/ts4.8/querystring.d.ts +131 -0
  95. package/package/node_modules/@types/node/ts4.8/readline/promises.d.ts +143 -0
  96. package/package/node_modules/@types/node/ts4.8/readline.d.ts +653 -0
  97. package/package/node_modules/@types/node/ts4.8/repl.d.ts +424 -0
  98. package/package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  99. package/package/node_modules/@types/node/ts4.8/stream/promises.d.ts +42 -0
  100. package/package/node_modules/@types/node/ts4.8/stream/web.d.ts +330 -0
  101. package/package/node_modules/@types/node/ts4.8/stream.d.ts +1340 -0
  102. package/package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  103. package/package/node_modules/@types/node/ts4.8/test.d.ts +314 -0
  104. package/package/node_modules/@types/node/ts4.8/timers/promises.d.ts +68 -0
  105. package/package/node_modules/@types/node/ts4.8/timers.d.ts +94 -0
  106. package/package/node_modules/@types/node/ts4.8/tls.d.ts +1028 -0
  107. package/package/node_modules/@types/node/ts4.8/trace_events.d.ts +171 -0
  108. package/package/node_modules/@types/node/ts4.8/tty.d.ts +206 -0
  109. package/package/node_modules/@types/node/ts4.8/url.d.ts +897 -0
  110. package/package/node_modules/@types/node/ts4.8/util.d.ts +1850 -0
  111. package/package/node_modules/@types/node/ts4.8/v8.d.ts +396 -0
  112. package/package/node_modules/@types/node/ts4.8/vm.d.ts +509 -0
  113. package/package/node_modules/@types/node/ts4.8/wasi.d.ts +158 -0
  114. package/package/node_modules/@types/node/ts4.8/worker_threads.d.ts +689 -0
  115. package/package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  116. package/package/node_modules/@types/node/tty.d.ts +206 -0
  117. package/package/node_modules/@types/node/url.d.ts +897 -0
  118. package/package/node_modules/@types/node/util.d.ts +1850 -0
  119. package/package/node_modules/@types/node/v8.d.ts +396 -0
  120. package/package/node_modules/@types/node/vm.d.ts +509 -0
  121. package/package/node_modules/@types/node/wasi.d.ts +158 -0
  122. package/package/node_modules/@types/node/worker_threads.d.ts +689 -0
  123. package/package/node_modules/@types/node/zlib.d.ts +517 -0
  124. package/package/node_modules/@types/nodemailer/LICENSE +21 -0
  125. package/package/node_modules/@types/nodemailer/README.md +16 -0
  126. package/package/node_modules/@types/nodemailer/index.d.ts +83 -0
  127. package/package/node_modules/@types/nodemailer/lib/addressparser/index.d.ts +31 -0
  128. package/package/node_modules/@types/nodemailer/lib/base64/index.d.ts +22 -0
  129. package/package/node_modules/@types/nodemailer/lib/dkim/index.d.ts +45 -0
  130. package/package/node_modules/@types/nodemailer/lib/dkim/message-parser.d.ts +75 -0
  131. package/package/node_modules/@types/nodemailer/lib/dkim/relaxed-body.d.ts +75 -0
  132. package/package/node_modules/@types/nodemailer/lib/dkim/sign.d.ts +11 -0
  133. package/package/node_modules/@types/nodemailer/lib/fetch/cookies.d.ts +54 -0
  134. package/package/node_modules/@types/nodemailer/lib/fetch/index.d.ts +38 -0
  135. package/package/node_modules/@types/nodemailer/lib/json-transport/index.d.ts +50 -0
  136. package/package/node_modules/@types/nodemailer/lib/mail-composer/index.d.ts +25 -0
  137. package/package/node_modules/@types/nodemailer/lib/mailer/index.d.ts +230 -0
  138. package/package/node_modules/@types/nodemailer/lib/mailer/mail-message.d.ts +28 -0
  139. package/package/node_modules/@types/nodemailer/lib/mime-funcs/index.d.ts +87 -0
  140. package/package/node_modules/@types/nodemailer/lib/mime-funcs/mime-types.d.ts +2 -0
  141. package/package/node_modules/@types/nodemailer/lib/mime-node/index.d.ts +137 -0
  142. package/package/node_modules/@types/nodemailer/lib/mime-node/last-newline.d.ts +9 -0
  143. package/package/node_modules/@types/nodemailer/lib/qp/index.d.ts +23 -0
  144. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/index.d.ts +53 -0
  145. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-unix.d.ts +7 -0
  146. package/package/node_modules/@types/nodemailer/lib/sendmail-transport/le-windows.d.ts +7 -0
  147. package/package/node_modules/@types/nodemailer/lib/ses-transport/index.d.ts +136 -0
  148. package/package/node_modules/@types/nodemailer/lib/shared/index.d.ts +51 -0
  149. package/package/node_modules/@types/nodemailer/lib/smtp-connection/data-stream.d.ts +11 -0
  150. package/package/node_modules/@types/nodemailer/lib/smtp-connection/http-proxy-client.d.ts +11 -0
  151. package/package/node_modules/@types/nodemailer/lib/smtp-connection/index.d.ts +254 -0
  152. package/package/node_modules/@types/nodemailer/lib/smtp-pool/index.d.ts +90 -0
  153. package/package/node_modules/@types/nodemailer/lib/smtp-pool/pool-resource.d.ts +66 -0
  154. package/package/node_modules/@types/nodemailer/lib/smtp-transport/index.d.ts +115 -0
  155. package/package/node_modules/@types/nodemailer/lib/stream-transport/index.d.ts +56 -0
  156. package/package/node_modules/@types/nodemailer/lib/well-known/index.d.ts +6 -0
  157. package/package/node_modules/@types/nodemailer/lib/xoauth2/index.d.ts +110 -0
  158. package/package/node_modules/@types/nodemailer/package.json +37 -0
  159. package/package/node_modules/nodemailer/.gitattributes +6 -0
  160. package/package/node_modules/nodemailer/.prettierrc.js +8 -0
  161. package/package/node_modules/nodemailer/CHANGELOG.md +715 -0
  162. package/package/node_modules/nodemailer/CODE_OF_CONDUCT.md +76 -0
  163. package/package/node_modules/nodemailer/CONTRIBUTING.md +67 -0
  164. package/package/node_modules/nodemailer/LICENSE +16 -0
  165. package/package/node_modules/nodemailer/README.md +93 -0
  166. package/package/node_modules/nodemailer/SECURITY.txt +22 -0
  167. package/package/node_modules/nodemailer/lib/addressparser/index.js +313 -0
  168. package/package/node_modules/nodemailer/lib/base64/index.js +142 -0
  169. package/package/node_modules/nodemailer/lib/dkim/index.js +251 -0
  170. package/package/node_modules/nodemailer/lib/dkim/message-parser.js +155 -0
  171. package/package/node_modules/nodemailer/lib/dkim/relaxed-body.js +154 -0
  172. package/package/node_modules/nodemailer/lib/dkim/sign.js +117 -0
  173. package/package/node_modules/nodemailer/lib/fetch/cookies.js +281 -0
  174. package/package/node_modules/nodemailer/lib/fetch/index.js +269 -0
  175. package/package/node_modules/nodemailer/lib/json-transport/index.js +82 -0
  176. package/package/node_modules/nodemailer/lib/mail-composer/index.js +558 -0
  177. package/package/node_modules/nodemailer/lib/mailer/index.js +427 -0
  178. package/package/node_modules/nodemailer/lib/mailer/mail-message.js +315 -0
  179. package/package/node_modules/nodemailer/lib/mime-funcs/index.js +619 -0
  180. package/package/node_modules/nodemailer/lib/mime-funcs/mime-types.js +2102 -0
  181. package/package/node_modules/nodemailer/lib/mime-node/index.js +1290 -0
  182. package/package/node_modules/nodemailer/lib/mime-node/last-newline.js +33 -0
  183. package/package/node_modules/nodemailer/lib/mime-node/le-unix.js +43 -0
  184. package/package/node_modules/nodemailer/lib/mime-node/le-windows.js +52 -0
  185. package/package/node_modules/nodemailer/lib/nodemailer.js +143 -0
  186. package/package/node_modules/nodemailer/lib/qp/index.js +219 -0
  187. package/package/node_modules/nodemailer/lib/sendmail-transport/index.js +210 -0
  188. package/package/node_modules/nodemailer/lib/ses-transport/index.js +349 -0
  189. package/package/node_modules/nodemailer/lib/shared/index.js +639 -0
  190. package/package/node_modules/nodemailer/lib/smtp-connection/data-stream.js +108 -0
  191. package/package/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +143 -0
  192. package/package/node_modules/nodemailer/lib/smtp-connection/index.js +1786 -0
  193. package/package/node_modules/nodemailer/lib/smtp-pool/index.js +648 -0
  194. package/package/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +253 -0
  195. package/package/node_modules/nodemailer/lib/smtp-transport/index.js +416 -0
  196. package/package/node_modules/nodemailer/lib/stream-transport/index.js +135 -0
  197. package/package/node_modules/nodemailer/lib/well-known/index.js +47 -0
  198. package/package/node_modules/nodemailer/lib/well-known/services.json +286 -0
  199. package/package/node_modules/nodemailer/lib/xoauth2/index.js +376 -0
  200. package/package/node_modules/nodemailer/package.json +46 -0
  201. package/package/node_modules/nodemailer/postinstall.js +101 -0
  202. package/package/package-lock.json +60 -0
  203. package/package/package.json +6 -0
  204. package/package.json +19 -0
@@ -0,0 +1,1614 @@
1
+ /**
2
+ * To use the HTTP server and client one must `require('http')`.
3
+ *
4
+ * The HTTP interfaces in Node.js are designed to support many features
5
+ * of the protocol which have been traditionally difficult to use.
6
+ * In particular, large, possibly chunk-encoded, messages. The interface is
7
+ * careful to never buffer entire requests or responses, so the
8
+ * user is able to stream data.
9
+ *
10
+ * HTTP message headers are represented by an object like this:
11
+ *
12
+ * ```js
13
+ * { 'content-length': '123',
14
+ * 'content-type': 'text/plain',
15
+ * 'connection': 'keep-alive',
16
+ * 'host': 'example.com',
17
+ * 'accept': '*' }
18
+ * ```
19
+ *
20
+ * Keys are lowercased. Values are not modified.
21
+ *
22
+ * In order to support the full spectrum of possible HTTP applications, the Node.js
23
+ * HTTP API is very low-level. It deals with stream handling and message
24
+ * parsing only. It parses a message into headers and body but it does not
25
+ * parse the actual headers or the body.
26
+ *
27
+ * See `message.headers` for details on how duplicate headers are handled.
28
+ *
29
+ * The raw headers as they were received are retained in the `rawHeaders`property, which is an array of `[key, value, key2, value2, ...]`. For
30
+ * example, the previous message header object might have a `rawHeaders`list like the following:
31
+ *
32
+ * ```js
33
+ * [ 'ConTent-Length', '123456',
34
+ * 'content-LENGTH', '123',
35
+ * 'content-type', 'text/plain',
36
+ * 'CONNECTION', 'keep-alive',
37
+ * 'Host', 'example.com',
38
+ * 'accepT', '*' ]
39
+ * ```
40
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/http.js)
41
+ */
42
+ declare module 'http' {
43
+ import * as stream from 'node:stream';
44
+ import { URL } from 'node:url';
45
+ import { TcpSocketConnectOpts, Socket, Server as NetServer, LookupFunction } from 'node:net';
46
+ // incoming headers will never contain number
47
+ interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
48
+ accept?: string | undefined;
49
+ 'accept-language'?: string | undefined;
50
+ 'accept-patch'?: string | undefined;
51
+ 'accept-ranges'?: string | undefined;
52
+ 'access-control-allow-credentials'?: string | undefined;
53
+ 'access-control-allow-headers'?: string | undefined;
54
+ 'access-control-allow-methods'?: string | undefined;
55
+ 'access-control-allow-origin'?: string | undefined;
56
+ 'access-control-expose-headers'?: string | undefined;
57
+ 'access-control-max-age'?: string | undefined;
58
+ 'access-control-request-headers'?: string | undefined;
59
+ 'access-control-request-method'?: string | undefined;
60
+ age?: string | undefined;
61
+ allow?: string | undefined;
62
+ 'alt-svc'?: string | undefined;
63
+ authorization?: string | undefined;
64
+ 'cache-control'?: string | undefined;
65
+ connection?: string | undefined;
66
+ 'content-disposition'?: string | undefined;
67
+ 'content-encoding'?: string | undefined;
68
+ 'content-language'?: string | undefined;
69
+ 'content-length'?: string | undefined;
70
+ 'content-location'?: string | undefined;
71
+ 'content-range'?: string | undefined;
72
+ 'content-type'?: string | undefined;
73
+ cookie?: string | undefined;
74
+ date?: string | undefined;
75
+ etag?: string | undefined;
76
+ expect?: string | undefined;
77
+ expires?: string | undefined;
78
+ forwarded?: string | undefined;
79
+ from?: string | undefined;
80
+ host?: string | undefined;
81
+ 'if-match'?: string | undefined;
82
+ 'if-modified-since'?: string | undefined;
83
+ 'if-none-match'?: string | undefined;
84
+ 'if-unmodified-since'?: string | undefined;
85
+ 'last-modified'?: string | undefined;
86
+ location?: string | undefined;
87
+ origin?: string | undefined;
88
+ pragma?: string | undefined;
89
+ 'proxy-authenticate'?: string | undefined;
90
+ 'proxy-authorization'?: string | undefined;
91
+ 'public-key-pins'?: string | undefined;
92
+ range?: string | undefined;
93
+ referer?: string | undefined;
94
+ 'retry-after'?: string | undefined;
95
+ 'sec-websocket-accept'?: string | undefined;
96
+ 'sec-websocket-extensions'?: string | undefined;
97
+ 'sec-websocket-key'?: string | undefined;
98
+ 'sec-websocket-protocol'?: string | undefined;
99
+ 'sec-websocket-version'?: string | undefined;
100
+ 'set-cookie'?: string[] | undefined;
101
+ 'strict-transport-security'?: string | undefined;
102
+ tk?: string | undefined;
103
+ trailer?: string | undefined;
104
+ 'transfer-encoding'?: string | undefined;
105
+ upgrade?: string | undefined;
106
+ 'user-agent'?: string | undefined;
107
+ vary?: string | undefined;
108
+ via?: string | undefined;
109
+ warning?: string | undefined;
110
+ 'www-authenticate'?: string | undefined;
111
+ }
112
+ // outgoing headers allows numbers (as they are converted internally to strings)
113
+ type OutgoingHttpHeader = number | string | string[];
114
+ interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {}
115
+ interface ClientRequestArgs {
116
+ signal?: AbortSignal | undefined;
117
+ protocol?: string | null | undefined;
118
+ host?: string | null | undefined;
119
+ hostname?: string | null | undefined;
120
+ family?: number | undefined;
121
+ port?: number | string | null | undefined;
122
+ defaultPort?: number | string | undefined;
123
+ localAddress?: string | undefined;
124
+ socketPath?: string | undefined;
125
+ /**
126
+ * @default 8192
127
+ */
128
+ maxHeaderSize?: number | undefined;
129
+ method?: string | undefined;
130
+ path?: string | null | undefined;
131
+ headers?: OutgoingHttpHeaders | undefined;
132
+ auth?: string | null | undefined;
133
+ agent?: Agent | boolean | undefined;
134
+ _defaultAgent?: Agent | undefined;
135
+ timeout?: number | undefined;
136
+ setHost?: boolean | undefined;
137
+ // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
138
+ createConnection?:
139
+ | ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket)
140
+ | undefined;
141
+ lookup?: LookupFunction | undefined;
142
+ }
143
+ interface ServerOptions<
144
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
145
+ Response extends typeof ServerResponse = typeof ServerResponse,
146
+ > {
147
+ IncomingMessage?: Request | undefined;
148
+ ServerResponse?: Response | undefined;
149
+ /**
150
+ * Optionally overrides the value of
151
+ * `--max-http-header-size` for requests received by this server, i.e.
152
+ * the maximum length of request headers in bytes.
153
+ * @default 8192
154
+ */
155
+ maxHeaderSize?: number | undefined;
156
+ /**
157
+ * Use an insecure HTTP parser that accepts invalid HTTP headers when true.
158
+ * Using the insecure parser should be avoided.
159
+ * See --insecure-http-parser for more information.
160
+ * @default false
161
+ */
162
+ insecureHTTPParser?: boolean | undefined;
163
+ /**
164
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
165
+ * @default false
166
+ * @since v16.5.0
167
+ */
168
+ noDelay?: boolean | undefined;
169
+ /**
170
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
171
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
172
+ * @default false
173
+ * @since v16.5.0
174
+ */
175
+ keepAlive?: boolean | undefined;
176
+ /**
177
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
178
+ * @default 0
179
+ * @since v16.5.0
180
+ */
181
+ keepAliveInitialDelay?: number | undefined;
182
+ }
183
+ type RequestListener<
184
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
185
+ Response extends typeof ServerResponse = typeof ServerResponse,
186
+ > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
187
+ /**
188
+ * @since v0.1.17
189
+ */
190
+ class Server<
191
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
192
+ Response extends typeof ServerResponse = typeof ServerResponse,
193
+ > extends NetServer {
194
+ constructor(requestListener?: RequestListener<Request, Response>);
195
+ constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
196
+ /**
197
+ * Sets the timeout value for sockets, and emits a `'timeout'` event on
198
+ * the Server object, passing the socket as an argument, if a timeout
199
+ * occurs.
200
+ *
201
+ * If there is a `'timeout'` event listener on the Server object, then it
202
+ * will be called with the timed-out socket as an argument.
203
+ *
204
+ * By default, the Server does not timeout sockets. However, if a callback
205
+ * is assigned to the Server's `'timeout'` event, timeouts must be handled
206
+ * explicitly.
207
+ * @since v0.9.12
208
+ * @param [msecs=0 (no timeout)]
209
+ */
210
+ setTimeout(msecs?: number, callback?: () => void): this;
211
+ setTimeout(callback: () => void): this;
212
+ /**
213
+ * Limits maximum incoming headers count. If set to 0, no limit will be applied.
214
+ * @since v0.7.0
215
+ */
216
+ maxHeadersCount: number | null;
217
+ /**
218
+ * The maximum number of requests socket can handle
219
+ * before closing keep alive connection.
220
+ *
221
+ * A value of `0` will disable the limit.
222
+ *
223
+ * When the limit is reached it will set the `Connection` header value to `close`,
224
+ * but will not actually close the connection, subsequent requests sent
225
+ * after the limit is reached will get `503 Service Unavailable` as a response.
226
+ * @since v16.10.0
227
+ */
228
+ maxRequestsPerSocket: number | null;
229
+ /**
230
+ * The number of milliseconds of inactivity before a socket is presumed
231
+ * to have timed out.
232
+ *
233
+ * A value of `0` will disable the timeout behavior on incoming connections.
234
+ *
235
+ * The socket timeout logic is set up on connection, so changing this
236
+ * value only affects new connections to the server, not any existing connections.
237
+ * @since v0.9.12
238
+ */
239
+ timeout: number;
240
+ /**
241
+ * Limit the amount of time the parser will wait to receive the complete HTTP
242
+ * headers.
243
+ *
244
+ * If the timeout expires, the server responds with status 408 without
245
+ * forwarding the request to the request listener and then closes the connection.
246
+ *
247
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
248
+ * potential Denial-of-Service attacks in case the server is deployed without a
249
+ * reverse proxy in front.
250
+ * @since v11.3.0, v10.14.0
251
+ */
252
+ headersTimeout: number;
253
+ /**
254
+ * The number of milliseconds of inactivity a server needs to wait for additional
255
+ * incoming data, after it has finished writing the last response, before a socket
256
+ * will be destroyed. If the server receives new data before the keep-alive
257
+ * timeout has fired, it will reset the regular inactivity timeout, i.e.,`server.timeout`.
258
+ *
259
+ * A value of `0` will disable the keep-alive timeout behavior on incoming
260
+ * connections.
261
+ * A value of `0` makes the http server behave similarly to Node.js versions prior
262
+ * to 8.0.0, which did not have a keep-alive timeout.
263
+ *
264
+ * The socket timeout logic is set up on connection, so changing this value only
265
+ * affects new connections to the server, not any existing connections.
266
+ * @since v8.0.0
267
+ */
268
+ keepAliveTimeout: number;
269
+ /**
270
+ * Sets the timeout value in milliseconds for receiving the entire request from
271
+ * the client.
272
+ *
273
+ * If the timeout expires, the server responds with status 408 without
274
+ * forwarding the request to the request listener and then closes the connection.
275
+ *
276
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
277
+ * potential Denial-of-Service attacks in case the server is deployed without a
278
+ * reverse proxy in front.
279
+ * @since v14.11.0
280
+ */
281
+ requestTimeout: number;
282
+ /**
283
+ * Closes all connections connected to this server.
284
+ * @since v18.2.0
285
+ */
286
+ closeAllConnections(): void;
287
+ /**
288
+ * Closes all connections connected to this server which are not sending a request or waiting for a response.
289
+ * @since v18.2.0
290
+ */
291
+ closeIdleConnections(): void;
292
+ addListener(event: string, listener: (...args: any[]) => void): this;
293
+ addListener(event: 'close', listener: () => void): this;
294
+ addListener(event: 'connection', listener: (socket: Socket) => void): this;
295
+ addListener(event: 'error', listener: (err: Error) => void): this;
296
+ addListener(event: 'listening', listener: () => void): this;
297
+ addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
298
+ addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
299
+ addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
300
+ addListener(
301
+ event: 'connect',
302
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
303
+ ): this;
304
+ addListener(event: 'request', listener: RequestListener<Request, Response>): this;
305
+ addListener(
306
+ event: 'upgrade',
307
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
308
+ ): this;
309
+ emit(event: string, ...args: any[]): boolean;
310
+ emit(event: 'close'): boolean;
311
+ emit(event: 'connection', socket: Socket): boolean;
312
+ emit(event: 'error', err: Error): boolean;
313
+ emit(event: 'listening'): boolean;
314
+ emit(
315
+ event: 'checkContinue',
316
+ req: InstanceType<Request>,
317
+ res: InstanceType<Response> & { req: InstanceType<Request> },
318
+ ): boolean;
319
+ emit(
320
+ event: 'checkExpectation',
321
+ req: InstanceType<Request>,
322
+ res: InstanceType<Response> & { req: InstanceType<Request> },
323
+ ): boolean;
324
+ emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
325
+ emit(event: 'connect', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
326
+ emit(
327
+ event: 'request',
328
+ req: InstanceType<Request>,
329
+ res: InstanceType<Response> & { req: InstanceType<Request> },
330
+ ): boolean;
331
+ emit(event: 'upgrade', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
332
+ on(event: string, listener: (...args: any[]) => void): this;
333
+ on(event: 'close', listener: () => void): this;
334
+ on(event: 'connection', listener: (socket: Socket) => void): this;
335
+ on(event: 'error', listener: (err: Error) => void): this;
336
+ on(event: 'listening', listener: () => void): this;
337
+ on(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
338
+ on(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
339
+ on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
340
+ on(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
341
+ on(event: 'request', listener: RequestListener<Request, Response>): this;
342
+ on(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
343
+ once(event: string, listener: (...args: any[]) => void): this;
344
+ once(event: 'close', listener: () => void): this;
345
+ once(event: 'connection', listener: (socket: Socket) => void): this;
346
+ once(event: 'error', listener: (err: Error) => void): this;
347
+ once(event: 'listening', listener: () => void): this;
348
+ once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
349
+ once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
350
+ once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
351
+ once(
352
+ event: 'connect',
353
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
354
+ ): this;
355
+ once(event: 'request', listener: RequestListener<Request, Response>): this;
356
+ once(
357
+ event: 'upgrade',
358
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
359
+ ): this;
360
+ prependListener(event: string, listener: (...args: any[]) => void): this;
361
+ prependListener(event: 'close', listener: () => void): this;
362
+ prependListener(event: 'connection', listener: (socket: Socket) => void): this;
363
+ prependListener(event: 'error', listener: (err: Error) => void): this;
364
+ prependListener(event: 'listening', listener: () => void): this;
365
+ prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
366
+ prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
367
+ prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
368
+ prependListener(
369
+ event: 'connect',
370
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
371
+ ): this;
372
+ prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
373
+ prependListener(
374
+ event: 'upgrade',
375
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
376
+ ): this;
377
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
378
+ prependOnceListener(event: 'close', listener: () => void): this;
379
+ prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
380
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
381
+ prependOnceListener(event: 'listening', listener: () => void): this;
382
+ prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
383
+ prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
384
+ prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
385
+ prependOnceListener(
386
+ event: 'connect',
387
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
388
+ ): this;
389
+ prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
390
+ prependOnceListener(
391
+ event: 'upgrade',
392
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
393
+ ): this;
394
+ }
395
+ /**
396
+ * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract of outgoing message from
397
+ * the perspective of the participants of HTTP transaction.
398
+ * @since v0.1.17
399
+ */
400
+ class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
401
+ readonly req: Request;
402
+ chunkedEncoding: boolean;
403
+ shouldKeepAlive: boolean;
404
+ useChunkedEncodingByDefault: boolean;
405
+ sendDate: boolean;
406
+ /**
407
+ * @deprecated Use `writableEnded` instead.
408
+ */
409
+ finished: boolean;
410
+ /**
411
+ * Read-only. `true` if the headers were sent, otherwise `false`.
412
+ * @since v0.9.3
413
+ */
414
+ readonly headersSent: boolean;
415
+ /**
416
+ * Aliases of `outgoingMessage.socket`
417
+ * @since v0.3.0
418
+ * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
419
+ */
420
+ readonly connection: Socket | null;
421
+ /**
422
+ * Reference to the underlying socket. Usually, users will not want to access
423
+ * this property.
424
+ *
425
+ * After calling `outgoingMessage.end()`, this property will be nulled.
426
+ * @since v0.3.0
427
+ */
428
+ readonly socket: Socket | null;
429
+ constructor();
430
+ /**
431
+ * Once a socket is associated with the message and is connected,`socket.setTimeout()` will be called with `msecs` as the first parameter.
432
+ * @since v0.9.12
433
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
434
+ */
435
+ setTimeout(msecs: number, callback?: () => void): this;
436
+ /**
437
+ * Sets a single header value for the header object.
438
+ * @since v0.4.0
439
+ * @param name Header name
440
+ * @param value Header value
441
+ */
442
+ setHeader(name: string, value: number | string | ReadonlyArray<string>): this;
443
+ /**
444
+ * Gets the value of HTTP header with the given name. If such a name doesn't
445
+ * exist in message, it will be `undefined`.
446
+ * @since v0.4.0
447
+ * @param name Name of header
448
+ */
449
+ getHeader(name: string): number | string | string[] | undefined;
450
+ /**
451
+ * Returns a shallow copy of the current outgoing headers. Since a shallow
452
+ * copy is used, array values may be mutated without additional calls to
453
+ * various header-related HTTP module methods. The keys of the returned
454
+ * object are the header names and the values are the respective header
455
+ * values. All header names are lowercase.
456
+ *
457
+ * The object returned by the `outgoingMessage.getHeaders()` method does
458
+ * not prototypically inherit from the JavaScript Object. This means that
459
+ * typical Object methods such as `obj.toString()`, `obj.hasOwnProperty()`,
460
+ * and others are not defined and will not work.
461
+ *
462
+ * ```js
463
+ * outgoingMessage.setHeader('Foo', 'bar');
464
+ * outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
465
+ *
466
+ * const headers = outgoingMessage.getHeaders();
467
+ * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
468
+ * ```
469
+ * @since v7.7.0
470
+ */
471
+ getHeaders(): OutgoingHttpHeaders;
472
+ /**
473
+ * Returns an array of names of headers of the outgoing outgoingMessage. All
474
+ * names are lowercase.
475
+ * @since v7.7.0
476
+ */
477
+ getHeaderNames(): string[];
478
+ /**
479
+ * Returns `true` if the header identified by `name` is currently set in the
480
+ * outgoing headers. The header name is case-insensitive.
481
+ *
482
+ * ```js
483
+ * const hasContentType = outgoingMessage.hasHeader('content-type');
484
+ * ```
485
+ * @since v7.7.0
486
+ */
487
+ hasHeader(name: string): boolean;
488
+ /**
489
+ * Removes a header that is queued for implicit sending.
490
+ *
491
+ * ```js
492
+ * outgoingMessage.removeHeader('Content-Encoding');
493
+ * ```
494
+ * @since v0.4.0
495
+ * @param name Header name
496
+ */
497
+ removeHeader(name: string): void;
498
+ /**
499
+ * Adds HTTP trailers (headers but at the end of the message) to the message.
500
+ *
501
+ * Trailers are **only** be emitted if the message is chunked encoded. If not,
502
+ * the trailer will be silently discarded.
503
+ *
504
+ * HTTP requires the `Trailer` header to be sent to emit trailers,
505
+ * with a list of header fields in its value, e.g.
506
+ *
507
+ * ```js
508
+ * message.writeHead(200, { 'Content-Type': 'text/plain',
509
+ * 'Trailer': 'Content-MD5' });
510
+ * message.write(fileData);
511
+ * message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
512
+ * message.end();
513
+ * ```
514
+ *
515
+ * Attempting to set a header field name or value that contains invalid characters
516
+ * will result in a `TypeError` being thrown.
517
+ * @since v0.3.0
518
+ */
519
+ addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
520
+ /**
521
+ * Compulsorily flushes the message headers
522
+ *
523
+ * For efficiency reason, Node.js normally buffers the message headers
524
+ * until `outgoingMessage.end()` is called or the first chunk of message data
525
+ * is written. It then tries to pack the headers and data into a single TCP
526
+ * packet.
527
+ *
528
+ * It is usually desired (it saves a TCP round-trip), but not when the first
529
+ * data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the request.
530
+ * @since v1.6.0
531
+ */
532
+ flushHeaders(): void;
533
+ }
534
+ /**
535
+ * This object is created internally by an HTTP server, not by the user. It is
536
+ * passed as the second parameter to the `'request'` event.
537
+ * @since v0.1.17
538
+ */
539
+ class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
540
+ /**
541
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
542
+ * this property controls the status code that will be sent to the client when
543
+ * the headers get flushed.
544
+ *
545
+ * ```js
546
+ * response.statusCode = 404;
547
+ * ```
548
+ *
549
+ * After response header was sent to the client, this property indicates the
550
+ * status code which was sent out.
551
+ * @since v0.4.0
552
+ */
553
+ statusCode: number;
554
+ /**
555
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
556
+ * this property controls the status message that will be sent to the client when
557
+ * the headers get flushed. If this is left as `undefined` then the standard
558
+ * message for the status code will be used.
559
+ *
560
+ * ```js
561
+ * response.statusMessage = 'Not found';
562
+ * ```
563
+ *
564
+ * After response header was sent to the client, this property indicates the
565
+ * status message which was sent out.
566
+ * @since v0.11.8
567
+ */
568
+ statusMessage: string;
569
+ constructor(req: Request);
570
+ assignSocket(socket: Socket): void;
571
+ detachSocket(socket: Socket): void;
572
+ /**
573
+ * Sends an HTTP/1.1 100 Continue message to the client, indicating that
574
+ * the request body should be sent. See the `'checkContinue'` event on`Server`.
575
+ * @since v0.3.0
576
+ */
577
+ writeContinue(callback?: () => void): void;
578
+ /**
579
+ * Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
580
+ * indicating that the user agent can preload/preconnect the linked resources.
581
+ * The `hints` is an object containing the values of headers to be sent with
582
+ * early hints message. The optional `callback` argument will be called when
583
+ * the response message has been written.
584
+ *
585
+ * Example:
586
+ *
587
+ * ```js
588
+ * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
589
+ * response.writeEarlyHints({
590
+ * 'link': earlyHintsLink,
591
+ * });
592
+ *
593
+ * const earlyHintsLinks = [
594
+ * '</styles.css>; rel=preload; as=style',
595
+ * '</scripts.js>; rel=preload; as=script',
596
+ * ];
597
+ * response.writeEarlyHints({
598
+ * 'link': earlyHintsLinks,
599
+ * 'x-trace-id': 'id for diagnostics'
600
+ * });
601
+ *
602
+ * const earlyHintsCallback = () => console.log('early hints message sent');
603
+ * response.writeEarlyHints({
604
+ * 'link': earlyHintsLinks
605
+ * }, earlyHintsCallback);
606
+ * ```
607
+ *
608
+ * @since v18.11.0
609
+ * @param hints An object containing the values of headers
610
+ * @param callback Will be called when the response message has been written
611
+ */
612
+ writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
613
+ /**
614
+ * Sends a response header to the request. The status code is a 3-digit HTTP
615
+ * status code, like `404`. The last argument, `headers`, are the response headers.
616
+ * Optionally one can give a human-readable `statusMessage` as the second
617
+ * argument.
618
+ *
619
+ * `headers` may be an `Array` where the keys and values are in the same list.
620
+ * It is _not_ a list of tuples. So, the even-numbered offsets are key values,
621
+ * and the odd-numbered offsets are the associated values. The array is in the same
622
+ * format as `request.rawHeaders`.
623
+ *
624
+ * Returns a reference to the `ServerResponse`, so that calls can be chained.
625
+ *
626
+ * ```js
627
+ * const body = 'hello world';
628
+ * response
629
+ * .writeHead(200, {
630
+ * 'Content-Length': Buffer.byteLength(body),
631
+ * 'Content-Type': 'text/plain'
632
+ * })
633
+ * .end(body);
634
+ * ```
635
+ *
636
+ * This method must only be called once on a message and it must
637
+ * be called before `response.end()` is called.
638
+ *
639
+ * If `response.write()` or `response.end()` are called before calling
640
+ * this, the implicit/mutable headers will be calculated and call this function.
641
+ *
642
+ * When headers have been set with `response.setHeader()`, they will be merged
643
+ * with any headers passed to `response.writeHead()`, with the headers passed
644
+ * to `response.writeHead()` given precedence.
645
+ *
646
+ * If this method is called and `response.setHeader()` has not been called,
647
+ * it will directly write the supplied header values onto the network channel
648
+ * without caching internally, and the `response.getHeader()` on the header
649
+ * will not yield the expected result. If progressive population of headers is
650
+ * desired with potential future retrieval and modification, use `response.setHeader()` instead.
651
+ *
652
+ * ```js
653
+ * // Returns content-type = text/plain
654
+ * const server = http.createServer((req, res) => {
655
+ * res.setHeader('Content-Type', 'text/html');
656
+ * res.setHeader('X-Foo', 'bar');
657
+ * res.writeHead(200, { 'Content-Type': 'text/plain' });
658
+ * res.end('ok');
659
+ * });
660
+ * ```
661
+ *
662
+ * `Content-Length` is given in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
663
+ * does not check whether `Content-Length` and the length of the body which has
664
+ * been transmitted are equal or not.
665
+ *
666
+ * Attempting to set a header field name or value that contains invalid characters
667
+ * will result in a `TypeError` being thrown.
668
+ * @since v0.1.30
669
+ */
670
+ writeHead(
671
+ statusCode: number,
672
+ statusMessage?: string,
673
+ headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
674
+ ): this;
675
+ writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
676
+ /**
677
+ * Sends an HTTP/1.1 102 Processing message to the client, indicating that
678
+ * the request body should be sent.
679
+ * @since v10.0.0
680
+ */
681
+ writeProcessing(): void;
682
+ }
683
+ interface InformationEvent {
684
+ statusCode: number;
685
+ statusMessage: string;
686
+ httpVersion: string;
687
+ httpVersionMajor: number;
688
+ httpVersionMinor: number;
689
+ headers: IncomingHttpHeaders;
690
+ rawHeaders: string[];
691
+ }
692
+ /**
693
+ * This object is created internally and returned from {@link request}. It
694
+ * represents an _in-progress_ request whose header has already been queued. The
695
+ * header is still mutable using the `setHeader(name, value)`,`getHeader(name)`, `removeHeader(name)` API. The actual header will
696
+ * be sent along with the first data chunk or when calling `request.end()`.
697
+ *
698
+ * To get the response, add a listener for `'response'` to the request object.`'response'` will be emitted from the request object when the response
699
+ * headers have been received. The `'response'` event is executed with one
700
+ * argument which is an instance of {@link IncomingMessage}.
701
+ *
702
+ * During the `'response'` event, one can add listeners to the
703
+ * response object; particularly to listen for the `'data'` event.
704
+ *
705
+ * If no `'response'` handler is added, then the response will be
706
+ * entirely discarded. However, if a `'response'` event handler is added,
707
+ * then the data from the response object **must** be consumed, either by
708
+ * calling `response.read()` whenever there is a `'readable'` event, or
709
+ * by adding a `'data'` handler, or by calling the `.resume()` method.
710
+ * Until the data is consumed, the `'end'` event will not fire. Also, until
711
+ * the data is read it will consume memory that can eventually lead to a
712
+ * 'process out of memory' error.
713
+ *
714
+ * For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered.
715
+ *
716
+ * Node.js does not check whether Content-Length and the length of the
717
+ * body which has been transmitted are equal or not.
718
+ * @since v0.1.17
719
+ */
720
+ class ClientRequest extends OutgoingMessage {
721
+ /**
722
+ * The `request.aborted` property will be `true` if the request has
723
+ * been aborted.
724
+ * @since v0.11.14
725
+ * @deprecated Since v17.0.0,v16.12.0 - Check `destroyed` instead.
726
+ */
727
+ aborted: boolean;
728
+ /**
729
+ * The request host.
730
+ * @since v14.5.0, v12.19.0
731
+ */
732
+ host: string;
733
+ /**
734
+ * The request protocol.
735
+ * @since v14.5.0, v12.19.0
736
+ */
737
+ protocol: string;
738
+ /**
739
+ * When sending request through a keep-alive enabled agent, the underlying socket
740
+ * might be reused. But if server closes connection at unfortunate time, client
741
+ * may run into a 'ECONNRESET' error.
742
+ *
743
+ * ```js
744
+ * const http = require('http');
745
+ *
746
+ * // Server has a 5 seconds keep-alive timeout by default
747
+ * http
748
+ * .createServer((req, res) => {
749
+ * res.write('hello\n');
750
+ * res.end();
751
+ * })
752
+ * .listen(3000);
753
+ *
754
+ * setInterval(() => {
755
+ * // Adapting a keep-alive agent
756
+ * http.get('http://localhost:3000', { agent }, (res) => {
757
+ * res.on('data', (data) => {
758
+ * // Do nothing
759
+ * });
760
+ * });
761
+ * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
762
+ * ```
763
+ *
764
+ * By marking a request whether it reused socket or not, we can do
765
+ * automatic error retry base on it.
766
+ *
767
+ * ```js
768
+ * const http = require('http');
769
+ * const agent = new http.Agent({ keepAlive: true });
770
+ *
771
+ * function retriableRequest() {
772
+ * const req = http
773
+ * .get('http://localhost:3000', { agent }, (res) => {
774
+ * // ...
775
+ * })
776
+ * .on('error', (err) => {
777
+ * // Check if retry is needed
778
+ * if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') {
779
+ * retriableRequest();
780
+ * }
781
+ * });
782
+ * }
783
+ *
784
+ * retriableRequest();
785
+ * ```
786
+ * @since v13.0.0, v12.16.0
787
+ */
788
+ reusedSocket: boolean;
789
+ /**
790
+ * Limits maximum response headers count. If set to 0, no limit will be applied.
791
+ */
792
+ maxHeadersCount: number;
793
+ constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
794
+ /**
795
+ * The request method.
796
+ * @since v0.1.97
797
+ */
798
+ method: string;
799
+ /**
800
+ * The request path.
801
+ * @since v0.4.0
802
+ */
803
+ path: string;
804
+ /**
805
+ * Marks the request as aborting. Calling this will cause remaining data
806
+ * in the response to be dropped and the socket to be destroyed.
807
+ * @since v0.3.8
808
+ * @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
809
+ */
810
+ abort(): void;
811
+ onSocket(socket: Socket): void;
812
+ /**
813
+ * Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
814
+ * @since v0.5.9
815
+ * @param timeout Milliseconds before a request times out.
816
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
817
+ */
818
+ setTimeout(timeout: number, callback?: () => void): this;
819
+ /**
820
+ * Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
821
+ * @since v0.5.9
822
+ */
823
+ setNoDelay(noDelay?: boolean): void;
824
+ /**
825
+ * Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
826
+ * @since v0.5.9
827
+ */
828
+ setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
829
+ /**
830
+ * Returns an array containing the unique names of the current outgoing raw
831
+ * headers. Header names are returned with their exact casing being set.
832
+ *
833
+ * ```js
834
+ * request.setHeader('Foo', 'bar');
835
+ * request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
836
+ *
837
+ * const headerNames = request.getRawHeaderNames();
838
+ * // headerNames === ['Foo', 'Set-Cookie']
839
+ * ```
840
+ * @since v15.13.0, v14.17.0
841
+ */
842
+ getRawHeaderNames(): string[];
843
+ /**
844
+ * @deprecated
845
+ */
846
+ addListener(event: 'abort', listener: () => void): this;
847
+ addListener(
848
+ event: 'connect',
849
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
850
+ ): this;
851
+ addListener(event: 'continue', listener: () => void): this;
852
+ addListener(event: 'information', listener: (info: InformationEvent) => void): this;
853
+ addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
854
+ addListener(event: 'socket', listener: (socket: Socket) => void): this;
855
+ addListener(event: 'timeout', listener: () => void): this;
856
+ addListener(
857
+ event: 'upgrade',
858
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
859
+ ): this;
860
+ addListener(event: 'close', listener: () => void): this;
861
+ addListener(event: 'drain', listener: () => void): this;
862
+ addListener(event: 'error', listener: (err: Error) => void): this;
863
+ addListener(event: 'finish', listener: () => void): this;
864
+ addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
865
+ addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
866
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
867
+ /**
868
+ * @deprecated
869
+ */
870
+ on(event: 'abort', listener: () => void): this;
871
+ on(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
872
+ on(event: 'continue', listener: () => void): this;
873
+ on(event: 'information', listener: (info: InformationEvent) => void): this;
874
+ on(event: 'response', listener: (response: IncomingMessage) => void): this;
875
+ on(event: 'socket', listener: (socket: Socket) => void): this;
876
+ on(event: 'timeout', listener: () => void): this;
877
+ on(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
878
+ on(event: 'close', listener: () => void): this;
879
+ on(event: 'drain', listener: () => void): this;
880
+ on(event: 'error', listener: (err: Error) => void): this;
881
+ on(event: 'finish', listener: () => void): this;
882
+ on(event: 'pipe', listener: (src: stream.Readable) => void): this;
883
+ on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
884
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
885
+ /**
886
+ * @deprecated
887
+ */
888
+ once(event: 'abort', listener: () => void): this;
889
+ once(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
890
+ once(event: 'continue', listener: () => void): this;
891
+ once(event: 'information', listener: (info: InformationEvent) => void): this;
892
+ once(event: 'response', listener: (response: IncomingMessage) => void): this;
893
+ once(event: 'socket', listener: (socket: Socket) => void): this;
894
+ once(event: 'timeout', listener: () => void): this;
895
+ once(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
896
+ once(event: 'close', listener: () => void): this;
897
+ once(event: 'drain', listener: () => void): this;
898
+ once(event: 'error', listener: (err: Error) => void): this;
899
+ once(event: 'finish', listener: () => void): this;
900
+ once(event: 'pipe', listener: (src: stream.Readable) => void): this;
901
+ once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
902
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
903
+ /**
904
+ * @deprecated
905
+ */
906
+ prependListener(event: 'abort', listener: () => void): this;
907
+ prependListener(
908
+ event: 'connect',
909
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
910
+ ): this;
911
+ prependListener(event: 'continue', listener: () => void): this;
912
+ prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
913
+ prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
914
+ prependListener(event: 'socket', listener: (socket: Socket) => void): this;
915
+ prependListener(event: 'timeout', listener: () => void): this;
916
+ prependListener(
917
+ event: 'upgrade',
918
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
919
+ ): this;
920
+ prependListener(event: 'close', listener: () => void): this;
921
+ prependListener(event: 'drain', listener: () => void): this;
922
+ prependListener(event: 'error', listener: (err: Error) => void): this;
923
+ prependListener(event: 'finish', listener: () => void): this;
924
+ prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
925
+ prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
926
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
927
+ /**
928
+ * @deprecated
929
+ */
930
+ prependOnceListener(event: 'abort', listener: () => void): this;
931
+ prependOnceListener(
932
+ event: 'connect',
933
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
934
+ ): this;
935
+ prependOnceListener(event: 'continue', listener: () => void): this;
936
+ prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
937
+ prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
938
+ prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
939
+ prependOnceListener(event: 'timeout', listener: () => void): this;
940
+ prependOnceListener(
941
+ event: 'upgrade',
942
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
943
+ ): this;
944
+ prependOnceListener(event: 'close', listener: () => void): this;
945
+ prependOnceListener(event: 'drain', listener: () => void): this;
946
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
947
+ prependOnceListener(event: 'finish', listener: () => void): this;
948
+ prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
949
+ prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
950
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
951
+ }
952
+ /**
953
+ * An `IncomingMessage` object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the `'request'` and `'response'` event respectively. It may be used to
954
+ * access response
955
+ * status, headers and data.
956
+ *
957
+ * Different from its `socket` value which is a subclass of `stream.Duplex`, the`IncomingMessage` itself extends `stream.Readable` and is created separately to
958
+ * parse and emit the incoming HTTP headers and payload, as the underlying socket
959
+ * may be reused multiple times in case of keep-alive.
960
+ * @since v0.1.17
961
+ */
962
+ class IncomingMessage extends stream.Readable {
963
+ constructor(socket: Socket);
964
+ /**
965
+ * The `message.aborted` property will be `true` if the request has
966
+ * been aborted.
967
+ * @since v10.1.0
968
+ * @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
969
+ */
970
+ aborted: boolean;
971
+ /**
972
+ * In case of server request, the HTTP version sent by the client. In the case of
973
+ * client response, the HTTP version of the connected-to server.
974
+ * Probably either `'1.1'` or `'1.0'`.
975
+ *
976
+ * Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
977
+ * @since v0.1.1
978
+ */
979
+ httpVersion: string;
980
+ httpVersionMajor: number;
981
+ httpVersionMinor: number;
982
+ /**
983
+ * The `message.complete` property will be `true` if a complete HTTP message has
984
+ * been received and successfully parsed.
985
+ *
986
+ * This property is particularly useful as a means of determining if a client or
987
+ * server fully transmitted a message before a connection was terminated:
988
+ *
989
+ * ```js
990
+ * const req = http.request({
991
+ * host: '127.0.0.1',
992
+ * port: 8080,
993
+ * method: 'POST'
994
+ * }, (res) => {
995
+ * res.resume();
996
+ * res.on('end', () => {
997
+ * if (!res.complete)
998
+ * console.error(
999
+ * 'The connection was terminated while the message was still being sent');
1000
+ * });
1001
+ * });
1002
+ * ```
1003
+ * @since v0.3.0
1004
+ */
1005
+ complete: boolean;
1006
+ /**
1007
+ * Alias for `message.socket`.
1008
+ * @since v0.1.90
1009
+ * @deprecated Since v16.0.0 - Use `socket`.
1010
+ */
1011
+ connection: Socket;
1012
+ /**
1013
+ * The `net.Socket` object associated with the connection.
1014
+ *
1015
+ * With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
1016
+ * client's authentication details.
1017
+ *
1018
+ * This property is guaranteed to be an instance of the `net.Socket` class,
1019
+ * a subclass of `stream.Duplex`, unless the user specified a socket
1020
+ * type other than `net.Socket` or internally nulled.
1021
+ * @since v0.3.0
1022
+ */
1023
+ socket: Socket;
1024
+ /**
1025
+ * The request/response headers object.
1026
+ *
1027
+ * Key-value pairs of header names and values. Header names are lower-cased.
1028
+ *
1029
+ * ```js
1030
+ * // Prints something like:
1031
+ * //
1032
+ * // { 'user-agent': 'curl/7.22.0',
1033
+ * // host: '127.0.0.1:8000',
1034
+ * // accept: '*' }
1035
+ * console.log(request.getHeaders());
1036
+ * ```
1037
+ *
1038
+ * Duplicates in raw headers are handled in the following ways, depending on the
1039
+ * header name:
1040
+ *
1041
+ * * Duplicates of `age`, `authorization`, `content-length`, `content-type`,`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,`last-modified`, `location`,
1042
+ * `max-forwards`, `proxy-authorization`, `referer`,`retry-after`, `server`, or `user-agent` are discarded.
1043
+ * * `set-cookie` is always an array. Duplicates are added to the array.
1044
+ * * For duplicate `cookie` headers, the values are joined together with '; '.
1045
+ * * For all other headers, the values are joined together with ', '.
1046
+ * @since v0.1.5
1047
+ */
1048
+ headers: IncomingHttpHeaders;
1049
+ /**
1050
+ * The raw request/response headers list exactly as they were received.
1051
+ *
1052
+ * The keys and values are in the same list. It is _not_ a
1053
+ * list of tuples. So, the even-numbered offsets are key values, and the
1054
+ * odd-numbered offsets are the associated values.
1055
+ *
1056
+ * Header names are not lowercased, and duplicates are not merged.
1057
+ *
1058
+ * ```js
1059
+ * // Prints something like:
1060
+ * //
1061
+ * // [ 'user-agent',
1062
+ * // 'this is invalid because there can be only one',
1063
+ * // 'User-Agent',
1064
+ * // 'curl/7.22.0',
1065
+ * // 'Host',
1066
+ * // '127.0.0.1:8000',
1067
+ * // 'ACCEPT',
1068
+ * // '*' ]
1069
+ * console.log(request.rawHeaders);
1070
+ * ```
1071
+ * @since v0.11.6
1072
+ */
1073
+ rawHeaders: string[];
1074
+ /**
1075
+ * The request/response trailers object. Only populated at the `'end'` event.
1076
+ * @since v0.3.0
1077
+ */
1078
+ trailers: NodeJS.Dict<string>;
1079
+ /**
1080
+ * The raw request/response trailer keys and values exactly as they were
1081
+ * received. Only populated at the `'end'` event.
1082
+ * @since v0.11.6
1083
+ */
1084
+ rawTrailers: string[];
1085
+ /**
1086
+ * Calls `message.socket.setTimeout(msecs, callback)`.
1087
+ * @since v0.5.9
1088
+ */
1089
+ setTimeout(msecs: number, callback?: () => void): this;
1090
+ /**
1091
+ * **Only valid for request obtained from {@link Server}.**
1092
+ *
1093
+ * The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
1094
+ * @since v0.1.1
1095
+ */
1096
+ method?: string | undefined;
1097
+ /**
1098
+ * **Only valid for request obtained from {@link Server}.**
1099
+ *
1100
+ * Request URL string. This contains only the URL that is present in the actual
1101
+ * HTTP request. Take the following request:
1102
+ *
1103
+ * ```http
1104
+ * GET /status?name=ryan HTTP/1.1
1105
+ * Accept: text/plain
1106
+ * ```
1107
+ *
1108
+ * To parse the URL into its parts:
1109
+ *
1110
+ * ```js
1111
+ * new URL(request.url, `http://${request.getHeaders().host}`);
1112
+ * ```
1113
+ *
1114
+ * When `request.url` is `'/status?name=ryan'` and`request.getHeaders().host` is `'localhost:3000'`:
1115
+ *
1116
+ * ```console
1117
+ * $ node
1118
+ * > new URL(request.url, `http://${request.getHeaders().host}`)
1119
+ * URL {
1120
+ * href: 'http://localhost:3000/status?name=ryan',
1121
+ * origin: 'http://localhost:3000',
1122
+ * protocol: 'http:',
1123
+ * username: '',
1124
+ * password: '',
1125
+ * host: 'localhost:3000',
1126
+ * hostname: 'localhost',
1127
+ * port: '3000',
1128
+ * pathname: '/status',
1129
+ * search: '?name=ryan',
1130
+ * searchParams: URLSearchParams { 'name' => 'ryan' },
1131
+ * hash: ''
1132
+ * }
1133
+ * ```
1134
+ * @since v0.1.90
1135
+ */
1136
+ url?: string | undefined;
1137
+ /**
1138
+ * **Only valid for response obtained from {@link ClientRequest}.**
1139
+ *
1140
+ * The 3-digit HTTP response status code. E.G. `404`.
1141
+ * @since v0.1.1
1142
+ */
1143
+ statusCode?: number | undefined;
1144
+ /**
1145
+ * **Only valid for response obtained from {@link ClientRequest}.**
1146
+ *
1147
+ * The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
1148
+ * @since v0.11.10
1149
+ */
1150
+ statusMessage?: string | undefined;
1151
+ /**
1152
+ * Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`is provided, an `'error'` event is emitted on the socket and `error` is passed
1153
+ * as an argument to any listeners on the event.
1154
+ * @since v0.3.0
1155
+ */
1156
+ destroy(error?: Error): this;
1157
+ }
1158
+ interface AgentOptions extends Partial<TcpSocketConnectOpts> {
1159
+ /**
1160
+ * Keep sockets around in a pool to be used by other requests in the future. Default = false
1161
+ */
1162
+ keepAlive?: boolean | undefined;
1163
+ /**
1164
+ * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
1165
+ * Only relevant if keepAlive is set to true.
1166
+ */
1167
+ keepAliveMsecs?: number | undefined;
1168
+ /**
1169
+ * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
1170
+ */
1171
+ maxSockets?: number | undefined;
1172
+ /**
1173
+ * Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
1174
+ */
1175
+ maxTotalSockets?: number | undefined;
1176
+ /**
1177
+ * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
1178
+ */
1179
+ maxFreeSockets?: number | undefined;
1180
+ /**
1181
+ * Socket timeout in milliseconds. This will set the timeout after the socket is connected.
1182
+ */
1183
+ timeout?: number | undefined;
1184
+ /**
1185
+ * Scheduling strategy to apply when picking the next free socket to use.
1186
+ * @default `lifo`
1187
+ */
1188
+ scheduling?: 'fifo' | 'lifo' | undefined;
1189
+ }
1190
+ /**
1191
+ * An `Agent` is responsible for managing connection persistence
1192
+ * and reuse for HTTP clients. It maintains a queue of pending requests
1193
+ * for a given host and port, reusing a single socket connection for each
1194
+ * until the queue is empty, at which time the socket is either destroyed
1195
+ * or put into a pool where it is kept to be used again for requests to the
1196
+ * same host and port. Whether it is destroyed or pooled depends on the`keepAlive` `option`.
1197
+ *
1198
+ * Pooled connections have TCP Keep-Alive enabled for them, but servers may
1199
+ * still close idle connections, in which case they will be removed from the
1200
+ * pool and a new connection will be made when a new HTTP request is made for
1201
+ * that host and port. Servers may also refuse to allow multiple requests
1202
+ * over the same connection, in which case the connection will have to be
1203
+ * remade for every request and cannot be pooled. The `Agent` will still make
1204
+ * the requests to that server, but each one will occur over a new connection.
1205
+ *
1206
+ * When a connection is closed by the client or the server, it is removed
1207
+ * from the pool. Any unused sockets in the pool will be unrefed so as not
1208
+ * to keep the Node.js process running when there are no outstanding requests.
1209
+ * (see `socket.unref()`).
1210
+ *
1211
+ * It is good practice, to `destroy()` an `Agent` instance when it is no
1212
+ * longer in use, because unused sockets consume OS resources.
1213
+ *
1214
+ * Sockets are removed from an agent when the socket emits either
1215
+ * a `'close'` event or an `'agentRemove'` event. When intending to keep one
1216
+ * HTTP request open for a long time without keeping it in the agent, something
1217
+ * like the following may be done:
1218
+ *
1219
+ * ```js
1220
+ * http.get(options, (res) => {
1221
+ * // Do stuff
1222
+ * }).on('socket', (socket) => {
1223
+ * socket.emit('agentRemove');
1224
+ * });
1225
+ * ```
1226
+ *
1227
+ * An agent may also be used for an individual request. By providing`{agent: false}` as an option to the `http.get()` or `http.request()`functions, a one-time use `Agent` with default options
1228
+ * will be used
1229
+ * for the client connection.
1230
+ *
1231
+ * `agent:false`:
1232
+ *
1233
+ * ```js
1234
+ * http.get({
1235
+ * hostname: 'localhost',
1236
+ * port: 80,
1237
+ * path: '/',
1238
+ * agent: false // Create a new agent just for this one request
1239
+ * }, (res) => {
1240
+ * // Do stuff with response
1241
+ * });
1242
+ * ```
1243
+ * @since v0.3.4
1244
+ */
1245
+ class Agent {
1246
+ /**
1247
+ * By default set to 256\. For agents with `keepAlive` enabled, this
1248
+ * sets the maximum number of sockets that will be left open in the free
1249
+ * state.
1250
+ * @since v0.11.7
1251
+ */
1252
+ maxFreeSockets: number;
1253
+ /**
1254
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1255
+ * can have open per origin. Origin is the returned value of `agent.getName()`.
1256
+ * @since v0.3.6
1257
+ */
1258
+ maxSockets: number;
1259
+ /**
1260
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1261
+ * can have open. Unlike `maxSockets`, this parameter applies across all origins.
1262
+ * @since v14.5.0, v12.19.0
1263
+ */
1264
+ maxTotalSockets: number;
1265
+ /**
1266
+ * An object which contains arrays of sockets currently awaiting use by
1267
+ * the agent when `keepAlive` is enabled. Do not modify.
1268
+ *
1269
+ * Sockets in the `freeSockets` list will be automatically destroyed and
1270
+ * removed from the array on `'timeout'`.
1271
+ * @since v0.11.4
1272
+ */
1273
+ readonly freeSockets: NodeJS.ReadOnlyDict<Socket[]>;
1274
+ /**
1275
+ * An object which contains arrays of sockets currently in use by the
1276
+ * agent. Do not modify.
1277
+ * @since v0.3.6
1278
+ */
1279
+ readonly sockets: NodeJS.ReadOnlyDict<Socket[]>;
1280
+ /**
1281
+ * An object which contains queues of requests that have not yet been assigned to
1282
+ * sockets. Do not modify.
1283
+ * @since v0.5.9
1284
+ */
1285
+ readonly requests: NodeJS.ReadOnlyDict<IncomingMessage[]>;
1286
+ constructor(opts?: AgentOptions);
1287
+ /**
1288
+ * Destroy any sockets that are currently in use by the agent.
1289
+ *
1290
+ * It is usually not necessary to do this. However, if using an
1291
+ * agent with `keepAlive` enabled, then it is best to explicitly shut down
1292
+ * the agent when it is no longer needed. Otherwise,
1293
+ * sockets might stay open for quite a long time before the server
1294
+ * terminates them.
1295
+ * @since v0.11.4
1296
+ */
1297
+ destroy(): void;
1298
+ }
1299
+ const METHODS: string[];
1300
+ const STATUS_CODES: {
1301
+ [errorCode: number]: string | undefined;
1302
+ [errorCode: string]: string | undefined;
1303
+ };
1304
+ /**
1305
+ * Returns a new instance of {@link Server}.
1306
+ *
1307
+ * The `requestListener` is a function which is automatically
1308
+ * added to the `'request'` event.
1309
+ * @since v0.1.13
1310
+ */
1311
+ function createServer<
1312
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1313
+ Response extends typeof ServerResponse = typeof ServerResponse,
1314
+ >(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
1315
+ function createServer<
1316
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1317
+ Response extends typeof ServerResponse = typeof ServerResponse,
1318
+ >(
1319
+ options: ServerOptions<Request, Response>,
1320
+ requestListener?: RequestListener<Request, Response>,
1321
+ ): Server<Request, Response>;
1322
+ // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
1323
+ // create interface RequestOptions would make the naming more clear to developers
1324
+ interface RequestOptions extends ClientRequestArgs {}
1325
+ /**
1326
+ * `options` in `socket.connect()` are also supported.
1327
+ *
1328
+ * Node.js maintains several connections per server to make HTTP requests.
1329
+ * This function allows one to transparently issue requests.
1330
+ *
1331
+ * `url` can be a string or a `URL` object. If `url` is a
1332
+ * string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
1333
+ *
1334
+ * If both `url` and `options` are specified, the objects are merged, with the`options` properties taking precedence.
1335
+ *
1336
+ * The optional `callback` parameter will be added as a one-time listener for
1337
+ * the `'response'` event.
1338
+ *
1339
+ * `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
1340
+ * upload a file with a POST request, then write to the `ClientRequest` object.
1341
+ *
1342
+ * ```js
1343
+ * const http = require('http');
1344
+ *
1345
+ * const postData = JSON.stringify({
1346
+ * 'msg': 'Hello World!'
1347
+ * });
1348
+ *
1349
+ * const options = {
1350
+ * hostname: 'www.google.com',
1351
+ * port: 80,
1352
+ * path: '/upload',
1353
+ * method: 'POST',
1354
+ * headers: {
1355
+ * 'Content-Type': 'application/json',
1356
+ * 'Content-Length': Buffer.byteLength(postData)
1357
+ * }
1358
+ * };
1359
+ *
1360
+ * const req = http.request(options, (res) => {
1361
+ * console.log(`STATUS: ${res.statusCode}`);
1362
+ * console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
1363
+ * res.setEncoding('utf8');
1364
+ * res.on('data', (chunk) => {
1365
+ * console.log(`BODY: ${chunk}`);
1366
+ * });
1367
+ * res.on('end', () => {
1368
+ * console.log('No more data in response.');
1369
+ * });
1370
+ * });
1371
+ *
1372
+ * req.on('error', (e) => {
1373
+ * console.error(`problem with request: ${e.message}`);
1374
+ * });
1375
+ *
1376
+ * // Write data to request body
1377
+ * req.write(postData);
1378
+ * req.end();
1379
+ * ```
1380
+ *
1381
+ * In the example `req.end()` was called. With `http.request()` one
1382
+ * must always call `req.end()` to signify the end of the request -
1383
+ * even if there is no data being written to the request body.
1384
+ *
1385
+ * If any error is encountered during the request (be that with DNS resolution,
1386
+ * TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
1387
+ * on the returned request object. As with all `'error'` events, if no listeners
1388
+ * are registered the error will be thrown.
1389
+ *
1390
+ * There are a few special headers that should be noted.
1391
+ *
1392
+ * * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
1393
+ * the server should be persisted until the next request.
1394
+ * * Sending a 'Content-Length' header will disable the default chunked encoding.
1395
+ * * Sending an 'Expect' header will immediately send the request headers.
1396
+ * Usually, when sending 'Expect: 100-continue', both a timeout and a listener
1397
+ * for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
1398
+ * information.
1399
+ * * Sending an Authorization header will override using the `auth` option
1400
+ * to compute basic authentication.
1401
+ *
1402
+ * Example using a `URL` as `options`:
1403
+ *
1404
+ * ```js
1405
+ * const options = new URL('http://abc:xyz@example.com');
1406
+ *
1407
+ * const req = http.request(options, (res) => {
1408
+ * // ...
1409
+ * });
1410
+ * ```
1411
+ *
1412
+ * In a successful request, the following events will be emitted in the following
1413
+ * order:
1414
+ *
1415
+ * * `'socket'`
1416
+ * * `'response'`
1417
+ * * `'data'` any number of times, on the `res` object
1418
+ * (`'data'` will not be emitted at all if the response body is empty, for
1419
+ * instance, in most redirects)
1420
+ * * `'end'` on the `res` object
1421
+ * * `'close'`
1422
+ *
1423
+ * In the case of a connection error, the following events will be emitted:
1424
+ *
1425
+ * * `'socket'`
1426
+ * * `'error'`
1427
+ * * `'close'`
1428
+ *
1429
+ * In the case of a premature connection close before the response is received,
1430
+ * the following events will be emitted in the following order:
1431
+ *
1432
+ * * `'socket'`
1433
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1434
+ * * `'close'`
1435
+ *
1436
+ * In the case of a premature connection close after the response is received,
1437
+ * the following events will be emitted in the following order:
1438
+ *
1439
+ * * `'socket'`
1440
+ * * `'response'`
1441
+ * * `'data'` any number of times, on the `res` object
1442
+ * * (connection closed here)
1443
+ * * `'aborted'` on the `res` object
1444
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1445
+ * * `'close'`
1446
+ * * `'close'` on the `res` object
1447
+ *
1448
+ * If `req.destroy()` is called before a socket is assigned, the following
1449
+ * events will be emitted in the following order:
1450
+ *
1451
+ * * (`req.destroy()` called here)
1452
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1453
+ * * `'close'`
1454
+ *
1455
+ * If `req.destroy()` is called before the connection succeeds, the following
1456
+ * events will be emitted in the following order:
1457
+ *
1458
+ * * `'socket'`
1459
+ * * (`req.destroy()` called here)
1460
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1461
+ * * `'close'`
1462
+ *
1463
+ * If `req.destroy()` is called after the response is received, the following
1464
+ * events will be emitted in the following order:
1465
+ *
1466
+ * * `'socket'`
1467
+ * * `'response'`
1468
+ * * `'data'` any number of times, on the `res` object
1469
+ * * (`req.destroy()` called here)
1470
+ * * `'aborted'` on the `res` object
1471
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1472
+ * * `'close'`
1473
+ * * `'close'` on the `res` object
1474
+ *
1475
+ * If `req.abort()` is called before a socket is assigned, the following
1476
+ * events will be emitted in the following order:
1477
+ *
1478
+ * * (`req.abort()` called here)
1479
+ * * `'abort'`
1480
+ * * `'close'`
1481
+ *
1482
+ * If `req.abort()` is called before the connection succeeds, the following
1483
+ * events will be emitted in the following order:
1484
+ *
1485
+ * * `'socket'`
1486
+ * * (`req.abort()` called here)
1487
+ * * `'abort'`
1488
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1489
+ * * `'close'`
1490
+ *
1491
+ * If `req.abort()` is called after the response is received, the following
1492
+ * events will be emitted in the following order:
1493
+ *
1494
+ * * `'socket'`
1495
+ * * `'response'`
1496
+ * * `'data'` any number of times, on the `res` object
1497
+ * * (`req.abort()` called here)
1498
+ * * `'abort'`
1499
+ * * `'aborted'` on the `res` object
1500
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1501
+ * * `'close'`
1502
+ * * `'close'` on the `res` object
1503
+ *
1504
+ * Setting the `timeout` option or using the `setTimeout()` function will
1505
+ * not abort the request or do anything besides add a `'timeout'` event.
1506
+ *
1507
+ * Passing an `AbortSignal` and then calling `abort` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
1508
+ * request itself.
1509
+ * @since v0.3.6
1510
+ */
1511
+ function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1512
+ function request(
1513
+ url: string | URL,
1514
+ options: RequestOptions,
1515
+ callback?: (res: IncomingMessage) => void,
1516
+ ): ClientRequest;
1517
+ /**
1518
+ * Since most requests are GET requests without bodies, Node.js provides this
1519
+ * convenience method. The only difference between this method and {@link request} is that it sets the method to GET and calls `req.end()`automatically. The callback must take care to consume the
1520
+ * response
1521
+ * data for reasons stated in {@link ClientRequest} section.
1522
+ *
1523
+ * The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
1524
+ *
1525
+ * JSON fetching example:
1526
+ *
1527
+ * ```js
1528
+ * http.get('http://localhost:8000/', (res) => {
1529
+ * const { statusCode } = res;
1530
+ * const contentType = res.headers['content-type'];
1531
+ *
1532
+ * let error;
1533
+ * // Any 2xx status code signals a successful response but
1534
+ * // here we're only checking for 200.
1535
+ * if (statusCode !== 200) {
1536
+ * error = new Error('Request Failed.\n' +
1537
+ * `Status Code: ${statusCode}`);
1538
+ * } else if (!/^application\/json/.test(contentType)) {
1539
+ * error = new Error('Invalid content-type.\n' +
1540
+ * `Expected application/json but received ${contentType}`);
1541
+ * }
1542
+ * if (error) {
1543
+ * console.error(error.message);
1544
+ * // Consume response data to free up memory
1545
+ * res.resume();
1546
+ * return;
1547
+ * }
1548
+ *
1549
+ * res.setEncoding('utf8');
1550
+ * let rawData = '';
1551
+ * res.on('data', (chunk) => { rawData += chunk; });
1552
+ * res.on('end', () => {
1553
+ * try {
1554
+ * const parsedData = JSON.parse(rawData);
1555
+ * console.log(parsedData);
1556
+ * } catch (e) {
1557
+ * console.error(e.message);
1558
+ * }
1559
+ * });
1560
+ * }).on('error', (e) => {
1561
+ * console.error(`Got error: ${e.message}`);
1562
+ * });
1563
+ *
1564
+ * // Create a local server to receive data from
1565
+ * const server = http.createServer((req, res) => {
1566
+ * res.writeHead(200, { 'Content-Type': 'application/json' });
1567
+ * res.end(JSON.stringify({
1568
+ * data: 'Hello World!'
1569
+ * }));
1570
+ * });
1571
+ *
1572
+ * server.listen(8000);
1573
+ * ```
1574
+ * @since v0.3.6
1575
+ * @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`. Properties that are inherited from the prototype are ignored.
1576
+ */
1577
+ function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1578
+ function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1579
+
1580
+ /**
1581
+ * Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
1582
+ * Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
1583
+ * @param name Header name
1584
+ * @since v14.3.0
1585
+ */
1586
+ function validateHeaderName(name: string): void;
1587
+ /**
1588
+ * Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
1589
+ * Passing illegal value as value will result in a TypeError being thrown.
1590
+ * - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
1591
+ * - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
1592
+ * @param name Header name
1593
+ * @param value Header value
1594
+ * @since v14.3.0
1595
+ */
1596
+ function validateHeaderValue(name: string, value: string): void;
1597
+
1598
+ /**
1599
+ * Set the maximum number of idle HTTP parsers. Default: 1000.
1600
+ * @param count
1601
+ * @since v18.8.0, v16.18.0
1602
+ */
1603
+ function setMaxIdleHTTPParsers(count: number): void;
1604
+
1605
+ let globalAgent: Agent;
1606
+ /**
1607
+ * Read-only property specifying the maximum allowed size of HTTP headers in bytes.
1608
+ * Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
1609
+ */
1610
+ const maxHeaderSize: number;
1611
+ }
1612
+ declare module 'node:http' {
1613
+ export * from 'http';
1614
+ }