bd6cf8725487c440cf8c16cbfb8bbd8cf494fc20f74db8b6c467a54810f47ec5d9612d23462bf5cc291d7fe23b0ae7b77e26880e56d3dd79d1e30d829021aa 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630
  1. /**
  2. * The `node:http2` module provides an implementation of the [HTTP/2](https://tools.ietf.org/html/rfc7540) protocol.
  3. * It can be accessed using:
  4. *
  5. * ```js
  6. * import http2 from 'node:http2';
  7. * ```
  8. * @since v8.4.0
  9. * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/http2.js)
  10. */
  11. declare module "http2" {
  12. import EventEmitter = require("node:events");
  13. import * as fs from "node:fs";
  14. import * as net from "node:net";
  15. import * as stream from "node:stream";
  16. import * as tls from "node:tls";
  17. import * as url from "node:url";
  18. import {
  19. IncomingHttpHeaders as Http1IncomingHttpHeaders,
  20. IncomingMessage,
  21. OutgoingHttpHeaders,
  22. ServerResponse,
  23. } from "node:http";
  24. export { OutgoingHttpHeaders } from "node:http";
  25. export interface IncomingHttpStatusHeader {
  26. ":status"?: number | undefined;
  27. }
  28. export interface IncomingHttpHeaders extends Http1IncomingHttpHeaders {
  29. ":path"?: string | undefined;
  30. ":method"?: string | undefined;
  31. ":authority"?: string | undefined;
  32. ":scheme"?: string | undefined;
  33. }
  34. // Http2Stream
  35. export interface StreamState {
  36. localWindowSize?: number | undefined;
  37. state?: number | undefined;
  38. localClose?: number | undefined;
  39. remoteClose?: number | undefined;
  40. /** @deprecated */
  41. sumDependencyWeight?: number | undefined;
  42. /** @deprecated */
  43. weight?: number | undefined;
  44. }
  45. export interface ServerStreamResponseOptions {
  46. endStream?: boolean | undefined;
  47. waitForTrailers?: boolean | undefined;
  48. }
  49. export interface StatOptions {
  50. offset: number;
  51. length: number;
  52. }
  53. export interface ServerStreamFileResponseOptions {
  54. // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
  55. statCheck?(stats: fs.Stats, headers: OutgoingHttpHeaders, statOptions: StatOptions): void | boolean;
  56. waitForTrailers?: boolean | undefined;
  57. offset?: number | undefined;
  58. length?: number | undefined;
  59. }
  60. export interface ServerStreamFileResponseOptionsWithError extends ServerStreamFileResponseOptions {
  61. onError?(err: NodeJS.ErrnoException): void;
  62. }
  63. export interface Http2Stream extends stream.Duplex {
  64. /**
  65. * Set to `true` if the `Http2Stream` instance was aborted abnormally. When set,
  66. * the `'aborted'` event will have been emitted.
  67. * @since v8.4.0
  68. */
  69. readonly aborted: boolean;
  70. /**
  71. * This property shows the number of characters currently buffered to be written.
  72. * See `net.Socket.bufferSize` for details.
  73. * @since v11.2.0, v10.16.0
  74. */
  75. readonly bufferSize: number;
  76. /**
  77. * Set to `true` if the `Http2Stream` instance has been closed.
  78. * @since v9.4.0
  79. */
  80. readonly closed: boolean;
  81. /**
  82. * Set to `true` if the `Http2Stream` instance has been destroyed and is no longer
  83. * usable.
  84. * @since v8.4.0
  85. */
  86. readonly destroyed: boolean;
  87. /**
  88. * Set to `true` if the `END_STREAM` flag was set in the request or response
  89. * HEADERS frame received, indicating that no additional data should be received
  90. * and the readable side of the `Http2Stream` will be closed.
  91. * @since v10.11.0
  92. */
  93. readonly endAfterHeaders: boolean;
  94. /**
  95. * The numeric stream identifier of this `Http2Stream` instance. Set to `undefined` if the stream identifier has not yet been assigned.
  96. * @since v8.4.0
  97. */
  98. readonly id?: number | undefined;
  99. /**
  100. * Set to `true` if the `Http2Stream` instance has not yet been assigned a
  101. * numeric stream identifier.
  102. * @since v9.4.0
  103. */
  104. readonly pending: boolean;
  105. /**
  106. * Set to the `RST_STREAM` `error code` reported when the `Http2Stream` is
  107. * destroyed after either receiving an `RST_STREAM` frame from the connected peer,
  108. * calling `http2stream.close()`, or `http2stream.destroy()`. Will be `undefined` if the `Http2Stream` has not been closed.
  109. * @since v8.4.0
  110. */
  111. readonly rstCode: number;
  112. /**
  113. * An object containing the outbound headers sent for this `Http2Stream`.
  114. * @since v9.5.0
  115. */
  116. readonly sentHeaders: OutgoingHttpHeaders;
  117. /**
  118. * An array of objects containing the outbound informational (additional) headers
  119. * sent for this `Http2Stream`.
  120. * @since v9.5.0
  121. */
  122. readonly sentInfoHeaders?: OutgoingHttpHeaders[] | undefined;
  123. /**
  124. * An object containing the outbound trailers sent for this `HttpStream`.
  125. * @since v9.5.0
  126. */
  127. readonly sentTrailers?: OutgoingHttpHeaders | undefined;
  128. /**
  129. * A reference to the `Http2Session` instance that owns this `Http2Stream`. The
  130. * value will be `undefined` after the `Http2Stream` instance is destroyed.
  131. * @since v8.4.0
  132. */
  133. readonly session: Http2Session | undefined;
  134. /**
  135. * Provides miscellaneous information about the current state of the `Http2Stream`.
  136. *
  137. * A current state of this `Http2Stream`.
  138. * @since v8.4.0
  139. */
  140. readonly state: StreamState;
  141. /**
  142. * Closes the `Http2Stream` instance by sending an `RST_STREAM` frame to the
  143. * connected HTTP/2 peer.
  144. * @since v8.4.0
  145. * @param [code=http2.constants.NGHTTP2_NO_ERROR] Unsigned 32-bit integer identifying the error code.
  146. * @param callback An optional function registered to listen for the `'close'` event.
  147. */
  148. close(code?: number, callback?: () => void): void;
  149. /**
  150. * @deprecated Priority signaling is no longer supported in Node.js.
  151. */
  152. priority(options: unknown): void;
  153. /**
  154. * ```js
  155. * import http2 from 'node:http2';
  156. * const client = http2.connect('http://example.org:8000');
  157. * const { NGHTTP2_CANCEL } = http2.constants;
  158. * const req = client.request({ ':path': '/' });
  159. *
  160. * // Cancel the stream if there's no activity after 5 seconds
  161. * req.setTimeout(5000, () => req.close(NGHTTP2_CANCEL));
  162. * ```
  163. * @since v8.4.0
  164. */
  165. setTimeout(msecs: number, callback?: () => void): void;
  166. /**
  167. * Sends a trailing `HEADERS` frame to the connected HTTP/2 peer. This method
  168. * will cause the `Http2Stream` to be immediately closed and must only be
  169. * called after the `'wantTrailers'` event has been emitted. When sending a
  170. * request or sending a response, the `options.waitForTrailers` option must be set
  171. * in order to keep the `Http2Stream` open after the final `DATA` frame so that
  172. * trailers can be sent.
  173. *
  174. * ```js
  175. * import http2 from 'node:http2';
  176. * const server = http2.createServer();
  177. * server.on('stream', (stream) => {
  178. * stream.respond(undefined, { waitForTrailers: true });
  179. * stream.on('wantTrailers', () => {
  180. * stream.sendTrailers({ xyz: 'abc' });
  181. * });
  182. * stream.end('Hello World');
  183. * });
  184. * ```
  185. *
  186. * The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header
  187. * fields (e.g. `':method'`, `':path'`, etc).
  188. * @since v10.0.0
  189. */
  190. sendTrailers(headers: OutgoingHttpHeaders): void;
  191. addListener(event: "aborted", listener: () => void): this;
  192. addListener(event: "close", listener: () => void): this;
  193. addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  194. addListener(event: "drain", listener: () => void): this;
  195. addListener(event: "end", listener: () => void): this;
  196. addListener(event: "error", listener: (err: Error) => void): this;
  197. addListener(event: "finish", listener: () => void): this;
  198. addListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
  199. addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  200. addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  201. addListener(event: "streamClosed", listener: (code: number) => void): this;
  202. addListener(event: "timeout", listener: () => void): this;
  203. addListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
  204. addListener(event: "wantTrailers", listener: () => void): this;
  205. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  206. emit(event: "aborted"): boolean;
  207. emit(event: "close"): boolean;
  208. emit(event: "data", chunk: Buffer | string): boolean;
  209. emit(event: "drain"): boolean;
  210. emit(event: "end"): boolean;
  211. emit(event: "error", err: Error): boolean;
  212. emit(event: "finish"): boolean;
  213. emit(event: "frameError", frameType: number, errorCode: number): boolean;
  214. emit(event: "pipe", src: stream.Readable): boolean;
  215. emit(event: "unpipe", src: stream.Readable): boolean;
  216. emit(event: "streamClosed", code: number): boolean;
  217. emit(event: "timeout"): boolean;
  218. emit(event: "trailers", trailers: IncomingHttpHeaders, flags: number): boolean;
  219. emit(event: "wantTrailers"): boolean;
  220. emit(event: string | symbol, ...args: any[]): boolean;
  221. on(event: "aborted", listener: () => void): this;
  222. on(event: "close", listener: () => void): this;
  223. on(event: "data", listener: (chunk: Buffer | string) => void): this;
  224. on(event: "drain", listener: () => void): this;
  225. on(event: "end", listener: () => void): this;
  226. on(event: "error", listener: (err: Error) => void): this;
  227. on(event: "finish", listener: () => void): this;
  228. on(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
  229. on(event: "pipe", listener: (src: stream.Readable) => void): this;
  230. on(event: "unpipe", listener: (src: stream.Readable) => void): this;
  231. on(event: "streamClosed", listener: (code: number) => void): this;
  232. on(event: "timeout", listener: () => void): this;
  233. on(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
  234. on(event: "wantTrailers", listener: () => void): this;
  235. on(event: string | symbol, listener: (...args: any[]) => void): this;
  236. once(event: "aborted", listener: () => void): this;
  237. once(event: "close", listener: () => void): this;
  238. once(event: "data", listener: (chunk: Buffer | string) => void): this;
  239. once(event: "drain", listener: () => void): this;
  240. once(event: "end", listener: () => void): this;
  241. once(event: "error", listener: (err: Error) => void): this;
  242. once(event: "finish", listener: () => void): this;
  243. once(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
  244. once(event: "pipe", listener: (src: stream.Readable) => void): this;
  245. once(event: "unpipe", listener: (src: stream.Readable) => void): this;
  246. once(event: "streamClosed", listener: (code: number) => void): this;
  247. once(event: "timeout", listener: () => void): this;
  248. once(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
  249. once(event: "wantTrailers", listener: () => void): this;
  250. once(event: string | symbol, listener: (...args: any[]) => void): this;
  251. prependListener(event: "aborted", listener: () => void): this;
  252. prependListener(event: "close", listener: () => void): this;
  253. prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  254. prependListener(event: "drain", listener: () => void): this;
  255. prependListener(event: "end", listener: () => void): this;
  256. prependListener(event: "error", listener: (err: Error) => void): this;
  257. prependListener(event: "finish", listener: () => void): this;
  258. prependListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
  259. prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  260. prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  261. prependListener(event: "streamClosed", listener: (code: number) => void): this;
  262. prependListener(event: "timeout", listener: () => void): this;
  263. prependListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
  264. prependListener(event: "wantTrailers", listener: () => void): this;
  265. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  266. prependOnceListener(event: "aborted", listener: () => void): this;
  267. prependOnceListener(event: "close", listener: () => void): this;
  268. prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  269. prependOnceListener(event: "drain", listener: () => void): this;
  270. prependOnceListener(event: "end", listener: () => void): this;
  271. prependOnceListener(event: "error", listener: (err: Error) => void): this;
  272. prependOnceListener(event: "finish", listener: () => void): this;
  273. prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number) => void): this;
  274. prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  275. prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  276. prependOnceListener(event: "streamClosed", listener: (code: number) => void): this;
  277. prependOnceListener(event: "timeout", listener: () => void): this;
  278. prependOnceListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
  279. prependOnceListener(event: "wantTrailers", listener: () => void): this;
  280. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  281. }
  282. export interface ClientHttp2Stream extends Http2Stream {
  283. addListener(event: "continue", listener: () => {}): this;
  284. addListener(
  285. event: "headers",
  286. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  287. ): this;
  288. addListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
  289. addListener(
  290. event: "response",
  291. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  292. ): this;
  293. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  294. emit(event: "continue"): boolean;
  295. emit(event: "headers", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
  296. emit(event: "push", headers: IncomingHttpHeaders, flags: number): boolean;
  297. emit(event: "response", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
  298. emit(event: string | symbol, ...args: any[]): boolean;
  299. on(event: "continue", listener: () => {}): this;
  300. on(
  301. event: "headers",
  302. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  303. ): this;
  304. on(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
  305. on(
  306. event: "response",
  307. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  308. ): this;
  309. on(event: string | symbol, listener: (...args: any[]) => void): this;
  310. once(event: "continue", listener: () => {}): this;
  311. once(
  312. event: "headers",
  313. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  314. ): this;
  315. once(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
  316. once(
  317. event: "response",
  318. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  319. ): this;
  320. once(event: string | symbol, listener: (...args: any[]) => void): this;
  321. prependListener(event: "continue", listener: () => {}): this;
  322. prependListener(
  323. event: "headers",
  324. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  325. ): this;
  326. prependListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
  327. prependListener(
  328. event: "response",
  329. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  330. ): this;
  331. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  332. prependOnceListener(event: "continue", listener: () => {}): this;
  333. prependOnceListener(
  334. event: "headers",
  335. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  336. ): this;
  337. prependOnceListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
  338. prependOnceListener(
  339. event: "response",
  340. listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
  341. ): this;
  342. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  343. }
  344. export interface ServerHttp2Stream extends Http2Stream {
  345. /**
  346. * True if headers were sent, false otherwise (read-only).
  347. * @since v8.4.0
  348. */
  349. readonly headersSent: boolean;
  350. /**
  351. * Read-only property mapped to the `SETTINGS_ENABLE_PUSH` flag of the remote
  352. * client's most recent `SETTINGS` frame. Will be `true` if the remote peer
  353. * accepts push streams, `false` otherwise. Settings are the same for every `Http2Stream` in the same `Http2Session`.
  354. * @since v8.4.0
  355. */
  356. readonly pushAllowed: boolean;
  357. /**
  358. * Sends an additional informational `HEADERS` frame to the connected HTTP/2 peer.
  359. * @since v8.4.0
  360. */
  361. additionalHeaders(headers: OutgoingHttpHeaders): void;
  362. /**
  363. * Initiates a push stream. The callback is invoked with the new `Http2Stream` instance created for the push stream passed as the second argument, or an `Error` passed as the first argument.
  364. *
  365. * ```js
  366. * import http2 from 'node:http2';
  367. * const server = http2.createServer();
  368. * server.on('stream', (stream) => {
  369. * stream.respond({ ':status': 200 });
  370. * stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
  371. * if (err) throw err;
  372. * pushStream.respond({ ':status': 200 });
  373. * pushStream.end('some pushed data');
  374. * });
  375. * stream.end('some data');
  376. * });
  377. * ```
  378. *
  379. * Setting the weight of a push stream is not allowed in the `HEADERS` frame. Pass
  380. * a `weight` value to `http2stream.priority` with the `silent` option set to `true` to enable server-side bandwidth balancing between concurrent streams.
  381. *
  382. * Calling `http2stream.pushStream()` from within a pushed stream is not permitted
  383. * and will throw an error.
  384. * @since v8.4.0
  385. * @param callback Callback that is called once the push stream has been initiated.
  386. */
  387. pushStream(
  388. headers: OutgoingHttpHeaders,
  389. callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void,
  390. ): void;
  391. pushStream(
  392. headers: OutgoingHttpHeaders,
  393. options?: Pick<ClientSessionRequestOptions, "exclusive" | "parent">,
  394. callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void,
  395. ): void;
  396. /**
  397. * ```js
  398. * import http2 from 'node:http2';
  399. * const server = http2.createServer();
  400. * server.on('stream', (stream) => {
  401. * stream.respond({ ':status': 200 });
  402. * stream.end('some data');
  403. * });
  404. * ```
  405. *
  406. * Initiates a response. When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
  407. * will be emitted immediately after queuing the last chunk of payload data to be sent.
  408. * The `http2stream.sendTrailers()` method can then be used to send trailing header fields to the peer.
  409. *
  410. * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
  411. * close when the final `DATA` frame is transmitted. User code must call either `http2stream.sendTrailers()` or `http2stream.close()` to close the `Http2Stream`.
  412. *
  413. * ```js
  414. * import http2 from 'node:http2';
  415. * const server = http2.createServer();
  416. * server.on('stream', (stream) => {
  417. * stream.respond({ ':status': 200 }, { waitForTrailers: true });
  418. * stream.on('wantTrailers', () => {
  419. * stream.sendTrailers({ ABC: 'some value to send' });
  420. * });
  421. * stream.end('some data');
  422. * });
  423. * ```
  424. * @since v8.4.0
  425. */
  426. respond(headers?: OutgoingHttpHeaders, options?: ServerStreamResponseOptions): void;
  427. /**
  428. * Initiates a response whose data is read from the given file descriptor. No
  429. * validation is performed on the given file descriptor. If an error occurs while
  430. * attempting to read data using the file descriptor, the `Http2Stream` will be
  431. * closed using an `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
  432. *
  433. * When used, the `Http2Stream` object's `Duplex` interface will be closed
  434. * automatically.
  435. *
  436. * ```js
  437. * import http2 from 'node:http2';
  438. * import fs from 'node:fs';
  439. *
  440. * const server = http2.createServer();
  441. * server.on('stream', (stream) => {
  442. * const fd = fs.openSync('/some/file', 'r');
  443. *
  444. * const stat = fs.fstatSync(fd);
  445. * const headers = {
  446. * 'content-length': stat.size,
  447. * 'last-modified': stat.mtime.toUTCString(),
  448. * 'content-type': 'text/plain; charset=utf-8',
  449. * };
  450. * stream.respondWithFD(fd, headers);
  451. * stream.on('close', () => fs.closeSync(fd));
  452. * });
  453. * ```
  454. *
  455. * The optional `options.statCheck` function may be specified to give user code
  456. * an opportunity to set additional content headers based on the `fs.Stat` details
  457. * of the given fd. If the `statCheck` function is provided, the `http2stream.respondWithFD()` method will
  458. * perform an `fs.fstat()` call to collect details on the provided file descriptor.
  459. *
  460. * The `offset` and `length` options may be used to limit the response to a
  461. * specific range subset. This can be used, for instance, to support HTTP Range
  462. * requests.
  463. *
  464. * The file descriptor or `FileHandle` is not closed when the stream is closed,
  465. * so it will need to be closed manually once it is no longer needed.
  466. * Using the same file descriptor concurrently for multiple streams
  467. * is not supported and may result in data loss. Re-using a file descriptor
  468. * after a stream has finished is supported.
  469. *
  470. * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
  471. * will be emitted immediately after queuing the last chunk of payload data to be
  472. * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
  473. * header fields to the peer.
  474. *
  475. * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
  476. * close when the final `DATA` frame is transmitted. User code _must_ call either `http2stream.sendTrailers()`
  477. * or `http2stream.close()` to close the `Http2Stream`.
  478. *
  479. * ```js
  480. * import http2 from 'node:http2';
  481. * import fs from 'node:fs';
  482. *
  483. * const server = http2.createServer();
  484. * server.on('stream', (stream) => {
  485. * const fd = fs.openSync('/some/file', 'r');
  486. *
  487. * const stat = fs.fstatSync(fd);
  488. * const headers = {
  489. * 'content-length': stat.size,
  490. * 'last-modified': stat.mtime.toUTCString(),
  491. * 'content-type': 'text/plain; charset=utf-8',
  492. * };
  493. * stream.respondWithFD(fd, headers, { waitForTrailers: true });
  494. * stream.on('wantTrailers', () => {
  495. * stream.sendTrailers({ ABC: 'some value to send' });
  496. * });
  497. *
  498. * stream.on('close', () => fs.closeSync(fd));
  499. * });
  500. * ```
  501. * @since v8.4.0
  502. * @param fd A readable file descriptor.
  503. */
  504. respondWithFD(
  505. fd: number | fs.promises.FileHandle,
  506. headers?: OutgoingHttpHeaders,
  507. options?: ServerStreamFileResponseOptions,
  508. ): void;
  509. /**
  510. * Sends a regular file as the response. The `path` must specify a regular file
  511. * or an `'error'` event will be emitted on the `Http2Stream` object.
  512. *
  513. * When used, the `Http2Stream` object's `Duplex` interface will be closed
  514. * automatically.
  515. *
  516. * The optional `options.statCheck` function may be specified to give user code
  517. * an opportunity to set additional content headers based on the `fs.Stat` details
  518. * of the given file:
  519. *
  520. * If an error occurs while attempting to read the file data, the `Http2Stream` will be closed using an
  521. * `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
  522. * If the `onError` callback is defined, then it will be called. Otherwise, the stream will be destroyed.
  523. *
  524. * Example using a file path:
  525. *
  526. * ```js
  527. * import http2 from 'node:http2';
  528. * const server = http2.createServer();
  529. * server.on('stream', (stream) => {
  530. * function statCheck(stat, headers) {
  531. * headers['last-modified'] = stat.mtime.toUTCString();
  532. * }
  533. *
  534. * function onError(err) {
  535. * // stream.respond() can throw if the stream has been destroyed by
  536. * // the other side.
  537. * try {
  538. * if (err.code === 'ENOENT') {
  539. * stream.respond({ ':status': 404 });
  540. * } else {
  541. * stream.respond({ ':status': 500 });
  542. * }
  543. * } catch (err) {
  544. * // Perform actual error handling.
  545. * console.error(err);
  546. * }
  547. * stream.end();
  548. * }
  549. *
  550. * stream.respondWithFile('/some/file',
  551. * { 'content-type': 'text/plain; charset=utf-8' },
  552. * { statCheck, onError });
  553. * });
  554. * ```
  555. *
  556. * The `options.statCheck` function may also be used to cancel the send operation
  557. * by returning `false`. For instance, a conditional request may check the stat
  558. * results to determine if the file has been modified to return an appropriate `304` response:
  559. *
  560. * ```js
  561. * import http2 from 'node:http2';
  562. * const server = http2.createServer();
  563. * server.on('stream', (stream) => {
  564. * function statCheck(stat, headers) {
  565. * // Check the stat here...
  566. * stream.respond({ ':status': 304 });
  567. * return false; // Cancel the send operation
  568. * }
  569. * stream.respondWithFile('/some/file',
  570. * { 'content-type': 'text/plain; charset=utf-8' },
  571. * { statCheck });
  572. * });
  573. * ```
  574. *
  575. * The `content-length` header field will be automatically set.
  576. *
  577. * The `offset` and `length` options may be used to limit the response to a
  578. * specific range subset. This can be used, for instance, to support HTTP Range
  579. * requests.
  580. *
  581. * The `options.onError` function may also be used to handle all the errors
  582. * that could happen before the delivery of the file is initiated. The
  583. * default behavior is to destroy the stream.
  584. *
  585. * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
  586. * will be emitted immediately after queuing the last chunk of payload data to be
  587. * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
  588. * header fields to the peer.
  589. *
  590. * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
  591. * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
  592. *
  593. * ```js
  594. * import http2 from 'node:http2';
  595. * const server = http2.createServer();
  596. * server.on('stream', (stream) => {
  597. * stream.respondWithFile('/some/file',
  598. * { 'content-type': 'text/plain; charset=utf-8' },
  599. * { waitForTrailers: true });
  600. * stream.on('wantTrailers', () => {
  601. * stream.sendTrailers({ ABC: 'some value to send' });
  602. * });
  603. * });
  604. * ```
  605. * @since v8.4.0
  606. */
  607. respondWithFile(
  608. path: string,
  609. headers?: OutgoingHttpHeaders,
  610. options?: ServerStreamFileResponseOptionsWithError,
  611. ): void;
  612. }
  613. // Http2Session
  614. export interface Settings {
  615. headerTableSize?: number | undefined;
  616. enablePush?: boolean | undefined;
  617. initialWindowSize?: number | undefined;
  618. maxFrameSize?: number | undefined;
  619. maxConcurrentStreams?: number | undefined;
  620. maxHeaderListSize?: number | undefined;
  621. enableConnectProtocol?: boolean | undefined;
  622. }
  623. export interface ClientSessionRequestOptions {
  624. endStream?: boolean | undefined;
  625. exclusive?: boolean | undefined;
  626. parent?: number | undefined;
  627. waitForTrailers?: boolean | undefined;
  628. signal?: AbortSignal | undefined;
  629. }
  630. export interface SessionState {
  631. effectiveLocalWindowSize?: number | undefined;
  632. effectiveRecvDataLength?: number | undefined;
  633. nextStreamID?: number | undefined;
  634. localWindowSize?: number | undefined;
  635. lastProcStreamID?: number | undefined;
  636. remoteWindowSize?: number | undefined;
  637. outboundQueueSize?: number | undefined;
  638. deflateDynamicTableSize?: number | undefined;
  639. inflateDynamicTableSize?: number | undefined;
  640. }
  641. export interface Http2Session extends EventEmitter {
  642. /**
  643. * Value will be `undefined` if the `Http2Session` is not yet connected to a
  644. * socket, `h2c` if the `Http2Session` is not connected to a `TLSSocket`, or
  645. * will return the value of the connected `TLSSocket`'s own `alpnProtocol` property.
  646. * @since v9.4.0
  647. */
  648. readonly alpnProtocol?: string | undefined;
  649. /**
  650. * Will be `true` if this `Http2Session` instance has been closed, otherwise `false`.
  651. * @since v9.4.0
  652. */
  653. readonly closed: boolean;
  654. /**
  655. * Will be `true` if this `Http2Session` instance is still connecting, will be set
  656. * to `false` before emitting `connect` event and/or calling the `http2.connect` callback.
  657. * @since v10.0.0
  658. */
  659. readonly connecting: boolean;
  660. /**
  661. * Will be `true` if this `Http2Session` instance has been destroyed and must no
  662. * longer be used, otherwise `false`.
  663. * @since v8.4.0
  664. */
  665. readonly destroyed: boolean;
  666. /**
  667. * Value is `undefined` if the `Http2Session` session socket has not yet been
  668. * connected, `true` if the `Http2Session` is connected with a `TLSSocket`,
  669. * and `false` if the `Http2Session` is connected to any other kind of socket
  670. * or stream.
  671. * @since v9.4.0
  672. */
  673. readonly encrypted?: boolean | undefined;
  674. /**
  675. * A prototype-less object describing the current local settings of this `Http2Session`.
  676. * The local settings are local to _this_`Http2Session` instance.
  677. * @since v8.4.0
  678. */
  679. readonly localSettings: Settings;
  680. /**
  681. * If the `Http2Session` is connected to a `TLSSocket`, the `originSet` property
  682. * will return an `Array` of origins for which the `Http2Session` may be
  683. * considered authoritative.
  684. *
  685. * The `originSet` property is only available when using a secure TLS connection.
  686. * @since v9.4.0
  687. */
  688. readonly originSet?: string[] | undefined;
  689. /**
  690. * Indicates whether the `Http2Session` is currently waiting for acknowledgment of
  691. * a sent `SETTINGS` frame. Will be `true` after calling the `http2session.settings()` method.
  692. * Will be `false` once all sent `SETTINGS` frames have been acknowledged.
  693. * @since v8.4.0
  694. */
  695. readonly pendingSettingsAck: boolean;
  696. /**
  697. * A prototype-less object describing the current remote settings of this`Http2Session`.
  698. * The remote settings are set by the _connected_ HTTP/2 peer.
  699. * @since v8.4.0
  700. */
  701. readonly remoteSettings: Settings;
  702. /**
  703. * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
  704. * limits available methods to ones safe to use with HTTP/2.
  705. *
  706. * `destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
  707. * an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information.
  708. *
  709. * `setTimeout` method will be called on this `Http2Session`.
  710. *
  711. * All other interactions will be routed directly to the socket.
  712. * @since v8.4.0
  713. */
  714. readonly socket: net.Socket | tls.TLSSocket;
  715. /**
  716. * Provides miscellaneous information about the current state of the`Http2Session`.
  717. *
  718. * An object describing the current status of this `Http2Session`.
  719. * @since v8.4.0
  720. */
  721. readonly state: SessionState;
  722. /**
  723. * The `http2session.type` will be equal to `http2.constants.NGHTTP2_SESSION_SERVER` if this `Http2Session` instance is a
  724. * server, and `http2.constants.NGHTTP2_SESSION_CLIENT` if the instance is a
  725. * client.
  726. * @since v8.4.0
  727. */
  728. readonly type: number;
  729. /**
  730. * Gracefully closes the `Http2Session`, allowing any existing streams to
  731. * complete on their own and preventing new `Http2Stream` instances from being
  732. * created. Once closed, `http2session.destroy()`_might_ be called if there
  733. * are no open `Http2Stream` instances.
  734. *
  735. * If specified, the `callback` function is registered as a handler for the`'close'` event.
  736. * @since v9.4.0
  737. */
  738. close(callback?: () => void): void;
  739. /**
  740. * Immediately terminates the `Http2Session` and the associated `net.Socket` or `tls.TLSSocket`.
  741. *
  742. * Once destroyed, the `Http2Session` will emit the `'close'` event. If `error` is not undefined, an `'error'` event will be emitted immediately before the `'close'` event.
  743. *
  744. * If there are any remaining open `Http2Streams` associated with the `Http2Session`, those will also be destroyed.
  745. * @since v8.4.0
  746. * @param error An `Error` object if the `Http2Session` is being destroyed due to an error.
  747. * @param code The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.
  748. */
  749. destroy(error?: Error, code?: number): void;
  750. /**
  751. * Transmits a `GOAWAY` frame to the connected peer _without_ shutting down the`Http2Session`.
  752. * @since v9.4.0
  753. * @param code An HTTP/2 error code
  754. * @param lastStreamID The numeric ID of the last processed `Http2Stream`
  755. * @param opaqueData A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.
  756. */
  757. goaway(code?: number, lastStreamID?: number, opaqueData?: NodeJS.ArrayBufferView): void;
  758. /**
  759. * Sends a `PING` frame to the connected HTTP/2 peer. A `callback` function must
  760. * be provided. The method will return `true` if the `PING` was sent, `false` otherwise.
  761. *
  762. * The maximum number of outstanding (unacknowledged) pings is determined by the `maxOutstandingPings` configuration option. The default maximum is 10.
  763. *
  764. * If provided, the `payload` must be a `Buffer`, `TypedArray`, or `DataView` containing 8 bytes of data that will be transmitted with the `PING` and
  765. * returned with the ping acknowledgment.
  766. *
  767. * The callback will be invoked with three arguments: an error argument that will
  768. * be `null` if the `PING` was successfully acknowledged, a `duration` argument
  769. * that reports the number of milliseconds elapsed since the ping was sent and the
  770. * acknowledgment was received, and a `Buffer` containing the 8-byte `PING` payload.
  771. *
  772. * ```js
  773. * session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
  774. * if (!err) {
  775. * console.log(`Ping acknowledged in ${duration} milliseconds`);
  776. * console.log(`With payload '${payload.toString()}'`);
  777. * }
  778. * });
  779. * ```
  780. *
  781. * If the `payload` argument is not specified, the default payload will be the
  782. * 64-bit timestamp (little endian) marking the start of the `PING` duration.
  783. * @since v8.9.3
  784. * @param payload Optional ping payload.
  785. */
  786. ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
  787. ping(
  788. payload: NodeJS.ArrayBufferView,
  789. callback: (err: Error | null, duration: number, payload: Buffer) => void,
  790. ): boolean;
  791. /**
  792. * Calls `ref()` on this `Http2Session` instance's underlying `net.Socket`.
  793. * @since v9.4.0
  794. */
  795. ref(): void;
  796. /**
  797. * Sets the local endpoint's window size.
  798. * The `windowSize` is the total window size to set, not
  799. * the delta.
  800. *
  801. * ```js
  802. * import http2 from 'node:http2';
  803. *
  804. * const server = http2.createServer();
  805. * const expectedWindowSize = 2 ** 20;
  806. * server.on('connect', (session) => {
  807. *
  808. * // Set local window size to be 2 ** 20
  809. * session.setLocalWindowSize(expectedWindowSize);
  810. * });
  811. * ```
  812. * @since v15.3.0, v14.18.0
  813. */
  814. setLocalWindowSize(windowSize: number): void;
  815. /**
  816. * Used to set a callback function that is called when there is no activity on
  817. * the `Http2Session` after `msecs` milliseconds. The given `callback` is
  818. * registered as a listener on the `'timeout'` event.
  819. * @since v8.4.0
  820. */
  821. setTimeout(msecs: number, callback?: () => void): void;
  822. /**
  823. * Updates the current local settings for this `Http2Session` and sends a new `SETTINGS` frame to the connected HTTP/2 peer.
  824. *
  825. * Once called, the `http2session.pendingSettingsAck` property will be `true` while the session is waiting for the remote peer to acknowledge the new
  826. * settings.
  827. *
  828. * The new settings will not become effective until the `SETTINGS` acknowledgment
  829. * is received and the `'localSettings'` event is emitted. It is possible to send
  830. * multiple `SETTINGS` frames while acknowledgment is still pending.
  831. * @since v8.4.0
  832. * @param callback Callback that is called once the session is connected or right away if the session is already connected.
  833. */
  834. settings(
  835. settings: Settings,
  836. callback?: (err: Error | null, settings: Settings, duration: number) => void,
  837. ): void;
  838. /**
  839. * Calls `unref()` on this `Http2Session`instance's underlying `net.Socket`.
  840. * @since v9.4.0
  841. */
  842. unref(): void;
  843. addListener(event: "close", listener: () => void): this;
  844. addListener(event: "error", listener: (err: Error) => void): this;
  845. addListener(
  846. event: "frameError",
  847. listener: (frameType: number, errorCode: number, streamID: number) => void,
  848. ): this;
  849. addListener(
  850. event: "goaway",
  851. listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void,
  852. ): this;
  853. addListener(event: "localSettings", listener: (settings: Settings) => void): this;
  854. addListener(event: "ping", listener: () => void): this;
  855. addListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
  856. addListener(event: "timeout", listener: () => void): this;
  857. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  858. emit(event: "close"): boolean;
  859. emit(event: "error", err: Error): boolean;
  860. emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean;
  861. emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: Buffer): boolean;
  862. emit(event: "localSettings", settings: Settings): boolean;
  863. emit(event: "ping"): boolean;
  864. emit(event: "remoteSettings", settings: Settings): boolean;
  865. emit(event: "timeout"): boolean;
  866. emit(event: string | symbol, ...args: any[]): boolean;
  867. on(event: "close", listener: () => void): this;
  868. on(event: "error", listener: (err: Error) => void): this;
  869. on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
  870. on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this;
  871. on(event: "localSettings", listener: (settings: Settings) => void): this;
  872. on(event: "ping", listener: () => void): this;
  873. on(event: "remoteSettings", listener: (settings: Settings) => void): this;
  874. on(event: "timeout", listener: () => void): this;
  875. on(event: string | symbol, listener: (...args: any[]) => void): this;
  876. once(event: "close", listener: () => void): this;
  877. once(event: "error", listener: (err: Error) => void): this;
  878. once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
  879. once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void): this;
  880. once(event: "localSettings", listener: (settings: Settings) => void): this;
  881. once(event: "ping", listener: () => void): this;
  882. once(event: "remoteSettings", listener: (settings: Settings) => void): this;
  883. once(event: "timeout", listener: () => void): this;
  884. once(event: string | symbol, listener: (...args: any[]) => void): this;
  885. prependListener(event: "close", listener: () => void): this;
  886. prependListener(event: "error", listener: (err: Error) => void): this;
  887. prependListener(
  888. event: "frameError",
  889. listener: (frameType: number, errorCode: number, streamID: number) => void,
  890. ): this;
  891. prependListener(
  892. event: "goaway",
  893. listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void,
  894. ): this;
  895. prependListener(event: "localSettings", listener: (settings: Settings) => void): this;
  896. prependListener(event: "ping", listener: () => void): this;
  897. prependListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
  898. prependListener(event: "timeout", listener: () => void): this;
  899. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  900. prependOnceListener(event: "close", listener: () => void): this;
  901. prependOnceListener(event: "error", listener: (err: Error) => void): this;
  902. prependOnceListener(
  903. event: "frameError",
  904. listener: (frameType: number, errorCode: number, streamID: number) => void,
  905. ): this;
  906. prependOnceListener(
  907. event: "goaway",
  908. listener: (errorCode: number, lastStreamID: number, opaqueData?: Buffer) => void,
  909. ): this;
  910. prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this;
  911. prependOnceListener(event: "ping", listener: () => void): this;
  912. prependOnceListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
  913. prependOnceListener(event: "timeout", listener: () => void): this;
  914. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  915. }
  916. export interface ClientHttp2Session extends Http2Session {
  917. /**
  918. * For HTTP/2 Client `Http2Session` instances only, the `http2session.request()` creates and returns an `Http2Stream` instance that can be used to send an
  919. * HTTP/2 request to the connected server.
  920. *
  921. * When a `ClientHttp2Session` is first created, the socket may not yet be
  922. * connected. if `clienthttp2session.request()` is called during this time, the
  923. * actual request will be deferred until the socket is ready to go.
  924. * If the `session` is closed before the actual request be executed, an `ERR_HTTP2_GOAWAY_SESSION` is thrown.
  925. *
  926. * This method is only available if `http2session.type` is equal to `http2.constants.NGHTTP2_SESSION_CLIENT`.
  927. *
  928. * ```js
  929. * import http2 from 'node:http2';
  930. * const clientSession = http2.connect('https://localhost:1234');
  931. * const {
  932. * HTTP2_HEADER_PATH,
  933. * HTTP2_HEADER_STATUS,
  934. * } = http2.constants;
  935. *
  936. * const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
  937. * req.on('response', (headers) => {
  938. * console.log(headers[HTTP2_HEADER_STATUS]);
  939. * req.on('data', (chunk) => { // .. });
  940. * req.on('end', () => { // .. });
  941. * });
  942. * ```
  943. *
  944. * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
  945. * is emitted immediately after queuing the last chunk of payload data to be sent.
  946. * The `http2stream.sendTrailers()` method can then be called to send trailing
  947. * headers to the peer.
  948. *
  949. * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
  950. * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
  951. *
  952. * When `options.signal` is set with an `AbortSignal` and then `abort` on the
  953. * corresponding `AbortController` is called, the request will emit an `'error'`event with an `AbortError` error.
  954. *
  955. * The `:method` and `:path` pseudo-headers are not specified within `headers`,
  956. * they respectively default to:
  957. *
  958. * * `:method` \= `'GET'`
  959. * * `:path` \= `/`
  960. * @since v8.4.0
  961. */
  962. request(
  963. headers?: OutgoingHttpHeaders | readonly string[],
  964. options?: ClientSessionRequestOptions,
  965. ): ClientHttp2Stream;
  966. addListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
  967. addListener(event: "origin", listener: (origins: string[]) => void): this;
  968. addListener(
  969. event: "connect",
  970. listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  971. ): this;
  972. addListener(
  973. event: "stream",
  974. listener: (
  975. stream: ClientHttp2Stream,
  976. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  977. flags: number,
  978. ) => void,
  979. ): this;
  980. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  981. emit(event: "altsvc", alt: string, origin: string, stream: number): boolean;
  982. emit(event: "origin", origins: readonly string[]): boolean;
  983. emit(event: "connect", session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
  984. emit(
  985. event: "stream",
  986. stream: ClientHttp2Stream,
  987. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  988. flags: number,
  989. ): boolean;
  990. emit(event: string | symbol, ...args: any[]): boolean;
  991. on(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
  992. on(event: "origin", listener: (origins: string[]) => void): this;
  993. on(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
  994. on(
  995. event: "stream",
  996. listener: (
  997. stream: ClientHttp2Stream,
  998. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  999. flags: number,
  1000. ) => void,
  1001. ): this;
  1002. on(event: string | symbol, listener: (...args: any[]) => void): this;
  1003. once(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
  1004. once(event: "origin", listener: (origins: string[]) => void): this;
  1005. once(
  1006. event: "connect",
  1007. listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  1008. ): this;
  1009. once(
  1010. event: "stream",
  1011. listener: (
  1012. stream: ClientHttp2Stream,
  1013. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  1014. flags: number,
  1015. ) => void,
  1016. ): this;
  1017. once(event: string | symbol, listener: (...args: any[]) => void): this;
  1018. prependListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
  1019. prependListener(event: "origin", listener: (origins: string[]) => void): this;
  1020. prependListener(
  1021. event: "connect",
  1022. listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  1023. ): this;
  1024. prependListener(
  1025. event: "stream",
  1026. listener: (
  1027. stream: ClientHttp2Stream,
  1028. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  1029. flags: number,
  1030. ) => void,
  1031. ): this;
  1032. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1033. prependOnceListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
  1034. prependOnceListener(event: "origin", listener: (origins: string[]) => void): this;
  1035. prependOnceListener(
  1036. event: "connect",
  1037. listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  1038. ): this;
  1039. prependOnceListener(
  1040. event: "stream",
  1041. listener: (
  1042. stream: ClientHttp2Stream,
  1043. headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
  1044. flags: number,
  1045. ) => void,
  1046. ): this;
  1047. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1048. }
  1049. export interface AlternativeServiceOptions {
  1050. origin: number | string | url.URL;
  1051. }
  1052. export interface ServerHttp2Session<
  1053. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1054. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1055. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1056. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1057. > extends Http2Session {
  1058. readonly server:
  1059. | Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>
  1060. | Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
  1061. /**
  1062. * Submits an `ALTSVC` frame (as defined by [RFC 7838](https://tools.ietf.org/html/rfc7838)) to the connected client.
  1063. *
  1064. * ```js
  1065. * import http2 from 'node:http2';
  1066. *
  1067. * const server = http2.createServer();
  1068. * server.on('session', (session) => {
  1069. * // Set altsvc for origin https://example.org:80
  1070. * session.altsvc('h2=":8000"', 'https://example.org:80');
  1071. * });
  1072. *
  1073. * server.on('stream', (stream) => {
  1074. * // Set altsvc for a specific stream
  1075. * stream.session.altsvc('h2=":8000"', stream.id);
  1076. * });
  1077. * ```
  1078. *
  1079. * Sending an `ALTSVC` frame with a specific stream ID indicates that the alternate
  1080. * service is associated with the origin of the given `Http2Stream`.
  1081. *
  1082. * The `alt` and origin string _must_ contain only ASCII bytes and are
  1083. * strictly interpreted as a sequence of ASCII bytes. The special value `'clear'`may be passed to clear any previously set alternative service for a given
  1084. * domain.
  1085. *
  1086. * When a string is passed for the `originOrStream` argument, it will be parsed as
  1087. * a URL and the origin will be derived. For instance, the origin for the
  1088. * HTTP URL `'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given string
  1089. * cannot be parsed as a URL or if a valid origin cannot be derived.
  1090. *
  1091. * A `URL` object, or any object with an `origin` property, may be passed as`originOrStream`, in which case the value of the `origin` property will be
  1092. * used. The value of the `origin` property _must_ be a properly serialized
  1093. * ASCII origin.
  1094. * @since v9.4.0
  1095. * @param alt A description of the alternative service configuration as defined by `RFC 7838`.
  1096. * @param originOrStream Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the
  1097. * `http2stream.id` property.
  1098. */
  1099. altsvc(alt: string, originOrStream: number | string | url.URL | AlternativeServiceOptions): void;
  1100. /**
  1101. * Submits an `ORIGIN` frame (as defined by [RFC 8336](https://tools.ietf.org/html/rfc8336)) to the connected client
  1102. * to advertise the set of origins for which the server is capable of providing
  1103. * authoritative responses.
  1104. *
  1105. * ```js
  1106. * import http2 from 'node:http2';
  1107. * const options = getSecureOptionsSomehow();
  1108. * const server = http2.createSecureServer(options);
  1109. * server.on('stream', (stream) => {
  1110. * stream.respond();
  1111. * stream.end('ok');
  1112. * });
  1113. * server.on('session', (session) => {
  1114. * session.origin('https://example.com', 'https://example.org');
  1115. * });
  1116. * ```
  1117. *
  1118. * When a string is passed as an `origin`, it will be parsed as a URL and the
  1119. * origin will be derived. For instance, the origin for the HTTP URL `'https://example.org/foo/bar'` is the ASCII string` 'https://example.org'`. An error will be thrown if either the given
  1120. * string
  1121. * cannot be parsed as a URL or if a valid origin cannot be derived.
  1122. *
  1123. * A `URL` object, or any object with an `origin` property, may be passed as
  1124. * an `origin`, in which case the value of the `origin` property will be
  1125. * used. The value of the `origin` property _must_ be a properly serialized
  1126. * ASCII origin.
  1127. *
  1128. * Alternatively, the `origins` option may be used when creating a new HTTP/2
  1129. * server using the `http2.createSecureServer()` method:
  1130. *
  1131. * ```js
  1132. * import http2 from 'node:http2';
  1133. * const options = getSecureOptionsSomehow();
  1134. * options.origins = ['https://example.com', 'https://example.org'];
  1135. * const server = http2.createSecureServer(options);
  1136. * server.on('stream', (stream) => {
  1137. * stream.respond();
  1138. * stream.end('ok');
  1139. * });
  1140. * ```
  1141. * @since v10.12.0
  1142. * @param origins One or more URL Strings passed as separate arguments.
  1143. */
  1144. origin(
  1145. ...origins: Array<
  1146. | string
  1147. | url.URL
  1148. | {
  1149. origin: string;
  1150. }
  1151. >
  1152. ): void;
  1153. addListener(
  1154. event: "connect",
  1155. listener: (
  1156. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1157. socket: net.Socket | tls.TLSSocket,
  1158. ) => void,
  1159. ): this;
  1160. addListener(
  1161. event: "stream",
  1162. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1163. ): this;
  1164. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1165. emit(
  1166. event: "connect",
  1167. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1168. socket: net.Socket | tls.TLSSocket,
  1169. ): boolean;
  1170. emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
  1171. emit(event: string | symbol, ...args: any[]): boolean;
  1172. on(
  1173. event: "connect",
  1174. listener: (
  1175. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1176. socket: net.Socket | tls.TLSSocket,
  1177. ) => void,
  1178. ): this;
  1179. on(
  1180. event: "stream",
  1181. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1182. ): this;
  1183. on(event: string | symbol, listener: (...args: any[]) => void): this;
  1184. once(
  1185. event: "connect",
  1186. listener: (
  1187. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1188. socket: net.Socket | tls.TLSSocket,
  1189. ) => void,
  1190. ): this;
  1191. once(
  1192. event: "stream",
  1193. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1194. ): this;
  1195. once(event: string | symbol, listener: (...args: any[]) => void): this;
  1196. prependListener(
  1197. event: "connect",
  1198. listener: (
  1199. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1200. socket: net.Socket | tls.TLSSocket,
  1201. ) => void,
  1202. ): this;
  1203. prependListener(
  1204. event: "stream",
  1205. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1206. ): this;
  1207. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1208. prependOnceListener(
  1209. event: "connect",
  1210. listener: (
  1211. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1212. socket: net.Socket | tls.TLSSocket,
  1213. ) => void,
  1214. ): this;
  1215. prependOnceListener(
  1216. event: "stream",
  1217. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1218. ): this;
  1219. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1220. }
  1221. // Http2Server
  1222. export interface SessionOptions {
  1223. /**
  1224. * Sets the maximum dynamic table size for deflating header fields.
  1225. * @default 4Kib
  1226. */
  1227. maxDeflateDynamicTableSize?: number | undefined;
  1228. /**
  1229. * Sets the maximum number of settings entries per `SETTINGS` frame.
  1230. * The minimum value allowed is `1`.
  1231. * @default 32
  1232. */
  1233. maxSettings?: number | undefined;
  1234. /**
  1235. * Sets the maximum memory that the `Http2Session` is permitted to use.
  1236. * The value is expressed in terms of number of megabytes, e.g. `1` equal 1 megabyte.
  1237. * The minimum value allowed is `1`.
  1238. * This is a credit based limit, existing `Http2Stream`s may cause this limit to be exceeded,
  1239. * but new `Http2Stream` instances will be rejected while this limit is exceeded.
  1240. * The current number of `Http2Stream` sessions, the current memory use of the header compression tables,
  1241. * current data queued to be sent, and unacknowledged `PING` and `SETTINGS` frames are all counted towards the current limit.
  1242. * @default 10
  1243. */
  1244. maxSessionMemory?: number | undefined;
  1245. /**
  1246. * Sets the maximum number of header entries.
  1247. * This is similar to `server.maxHeadersCount` or `request.maxHeadersCount` in the `node:http` module.
  1248. * The minimum value is `1`.
  1249. * @default 128
  1250. */
  1251. maxHeaderListPairs?: number | undefined;
  1252. /**
  1253. * Sets the maximum number of outstanding, unacknowledged pings.
  1254. * @default 10
  1255. */
  1256. maxOutstandingPings?: number | undefined;
  1257. /**
  1258. * Sets the maximum allowed size for a serialized, compressed block of headers.
  1259. * Attempts to send headers that exceed this limit will result in
  1260. * a `'frameError'` event being emitted and the stream being closed and destroyed.
  1261. */
  1262. maxSendHeaderBlockLength?: number | undefined;
  1263. /**
  1264. * Strategy used for determining the amount of padding to use for `HEADERS` and `DATA` frames.
  1265. * @default http2.constants.PADDING_STRATEGY_NONE
  1266. */
  1267. paddingStrategy?: number | undefined;
  1268. /**
  1269. * Sets the maximum number of concurrent streams for the remote peer as if a `SETTINGS` frame had been received.
  1270. * Will be overridden if the remote peer sets its own value for `maxConcurrentStreams`.
  1271. * @default 100
  1272. */
  1273. peerMaxConcurrentStreams?: number | undefined;
  1274. /**
  1275. * The initial settings to send to the remote peer upon connection.
  1276. */
  1277. settings?: Settings | undefined;
  1278. /**
  1279. * The array of integer values determines the settings types,
  1280. * which are included in the `CustomSettings`-property of the received remoteSettings.
  1281. * Please see the `CustomSettings`-property of the `Http2Settings` object for more information, on the allowed setting types.
  1282. */
  1283. remoteCustomSettings?: number[] | undefined;
  1284. /**
  1285. * Specifies a timeout in milliseconds that
  1286. * a server should wait when an [`'unknownProtocol'`][] is emitted. If the
  1287. * socket has not been destroyed by that time the server will destroy it.
  1288. * @default 100000
  1289. */
  1290. unknownProtocolTimeout?: number | undefined;
  1291. /**
  1292. * If `true`, it turns on strict leading
  1293. * and trailing whitespace validation for HTTP/2 header field names and values
  1294. * as per [RFC-9113](https://www.rfc-editor.org/rfc/rfc9113.html#section-8.2.1).
  1295. * @since v24.2.0
  1296. * @default true
  1297. */
  1298. strictFieldWhitespaceValidation?: boolean | undefined;
  1299. }
  1300. export interface ClientSessionOptions extends SessionOptions {
  1301. /**
  1302. * Sets the maximum number of reserved push streams the client will accept at any given time.
  1303. * Once the current number of currently reserved push streams exceeds reaches this limit,
  1304. * new push streams sent by the server will be automatically rejected.
  1305. * The minimum allowed value is 0. The maximum allowed value is 2<sup>32</sup>-1.
  1306. * A negative value sets this option to the maximum allowed value.
  1307. * @default 200
  1308. */
  1309. maxReservedRemoteStreams?: number | undefined;
  1310. /**
  1311. * An optional callback that receives the `URL` instance passed to `connect` and the `options` object,
  1312. * and returns any `Duplex` stream that is to be used as the connection for this session.
  1313. */
  1314. createConnection?: ((authority: url.URL, option: SessionOptions) => stream.Duplex) | undefined;
  1315. /**
  1316. * The protocol to connect with, if not set in the `authority`.
  1317. * Value may be either `'http:'` or `'https:'`.
  1318. * @default 'https:'
  1319. */
  1320. protocol?: "http:" | "https:" | undefined;
  1321. }
  1322. export interface ServerSessionOptions<
  1323. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1324. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1325. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1326. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1327. > extends SessionOptions {
  1328. streamResetBurst?: number | undefined;
  1329. streamResetRate?: number | undefined;
  1330. Http1IncomingMessage?: Http1Request | undefined;
  1331. Http1ServerResponse?: Http1Response | undefined;
  1332. Http2ServerRequest?: Http2Request | undefined;
  1333. Http2ServerResponse?: Http2Response | undefined;
  1334. }
  1335. export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
  1336. export interface SecureServerSessionOptions<
  1337. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1338. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1339. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1340. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1341. > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response>, tls.TlsOptions {}
  1342. export interface ServerOptions<
  1343. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1344. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1345. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1346. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1347. > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {}
  1348. export interface SecureServerOptions<
  1349. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1350. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1351. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1352. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1353. > extends SecureServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {
  1354. allowHTTP1?: boolean | undefined;
  1355. origins?: string[] | undefined;
  1356. }
  1357. interface HTTP2ServerCommon {
  1358. setTimeout(msec?: number, callback?: () => void): this;
  1359. /**
  1360. * Throws ERR_HTTP2_INVALID_SETTING_VALUE for invalid settings values.
  1361. * Throws ERR_INVALID_ARG_TYPE for invalid settings argument.
  1362. */
  1363. updateSettings(settings: Settings): void;
  1364. }
  1365. export interface Http2Server<
  1366. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1367. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1368. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1369. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1370. > extends net.Server, HTTP2ServerCommon {
  1371. addListener(
  1372. event: "checkContinue",
  1373. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1374. ): this;
  1375. addListener(
  1376. event: "request",
  1377. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1378. ): this;
  1379. addListener(
  1380. event: "session",
  1381. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1382. ): this;
  1383. addListener(event: "sessionError", listener: (err: Error) => void): this;
  1384. addListener(
  1385. event: "stream",
  1386. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1387. ): this;
  1388. addListener(event: "timeout", listener: () => void): this;
  1389. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1390. emit(
  1391. event: "checkContinue",
  1392. request: InstanceType<Http2Request>,
  1393. response: InstanceType<Http2Response>,
  1394. ): boolean;
  1395. emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
  1396. emit(
  1397. event: "session",
  1398. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1399. ): boolean;
  1400. emit(event: "sessionError", err: Error): boolean;
  1401. emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
  1402. emit(event: "timeout"): boolean;
  1403. emit(event: string | symbol, ...args: any[]): boolean;
  1404. on(
  1405. event: "checkContinue",
  1406. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1407. ): this;
  1408. on(
  1409. event: "request",
  1410. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1411. ): this;
  1412. on(
  1413. event: "session",
  1414. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1415. ): this;
  1416. on(event: "sessionError", listener: (err: Error) => void): this;
  1417. on(
  1418. event: "stream",
  1419. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1420. ): this;
  1421. on(event: "timeout", listener: () => void): this;
  1422. on(event: string | symbol, listener: (...args: any[]) => void): this;
  1423. once(
  1424. event: "checkContinue",
  1425. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1426. ): this;
  1427. once(
  1428. event: "request",
  1429. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1430. ): this;
  1431. once(
  1432. event: "session",
  1433. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1434. ): this;
  1435. once(event: "sessionError", listener: (err: Error) => void): this;
  1436. once(
  1437. event: "stream",
  1438. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1439. ): this;
  1440. once(event: "timeout", listener: () => void): this;
  1441. once(event: string | symbol, listener: (...args: any[]) => void): this;
  1442. prependListener(
  1443. event: "checkContinue",
  1444. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1445. ): this;
  1446. prependListener(
  1447. event: "request",
  1448. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1449. ): this;
  1450. prependListener(
  1451. event: "session",
  1452. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1453. ): this;
  1454. prependListener(event: "sessionError", listener: (err: Error) => void): this;
  1455. prependListener(
  1456. event: "stream",
  1457. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1458. ): this;
  1459. prependListener(event: "timeout", listener: () => void): this;
  1460. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1461. prependOnceListener(
  1462. event: "checkContinue",
  1463. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1464. ): this;
  1465. prependOnceListener(
  1466. event: "request",
  1467. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1468. ): this;
  1469. prependOnceListener(
  1470. event: "session",
  1471. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1472. ): this;
  1473. prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
  1474. prependOnceListener(
  1475. event: "stream",
  1476. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1477. ): this;
  1478. prependOnceListener(event: "timeout", listener: () => void): this;
  1479. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1480. }
  1481. export interface Http2SecureServer<
  1482. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  1483. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  1484. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  1485. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  1486. > extends tls.Server, HTTP2ServerCommon {
  1487. addListener(
  1488. event: "checkContinue",
  1489. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1490. ): this;
  1491. addListener(
  1492. event: "request",
  1493. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1494. ): this;
  1495. addListener(
  1496. event: "session",
  1497. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1498. ): this;
  1499. addListener(event: "sessionError", listener: (err: Error) => void): this;
  1500. addListener(
  1501. event: "stream",
  1502. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1503. ): this;
  1504. addListener(event: "timeout", listener: () => void): this;
  1505. addListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
  1506. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1507. emit(
  1508. event: "checkContinue",
  1509. request: InstanceType<Http2Request>,
  1510. response: InstanceType<Http2Response>,
  1511. ): boolean;
  1512. emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
  1513. emit(
  1514. event: "session",
  1515. session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
  1516. ): boolean;
  1517. emit(event: "sessionError", err: Error): boolean;
  1518. emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
  1519. emit(event: "timeout"): boolean;
  1520. emit(event: "unknownProtocol", socket: tls.TLSSocket): boolean;
  1521. emit(event: string | symbol, ...args: any[]): boolean;
  1522. on(
  1523. event: "checkContinue",
  1524. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1525. ): this;
  1526. on(
  1527. event: "request",
  1528. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1529. ): this;
  1530. on(
  1531. event: "session",
  1532. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1533. ): this;
  1534. on(event: "sessionError", listener: (err: Error) => void): this;
  1535. on(
  1536. event: "stream",
  1537. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1538. ): this;
  1539. on(event: "timeout", listener: () => void): this;
  1540. on(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
  1541. on(event: string | symbol, listener: (...args: any[]) => void): this;
  1542. once(
  1543. event: "checkContinue",
  1544. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1545. ): this;
  1546. once(
  1547. event: "request",
  1548. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1549. ): this;
  1550. once(
  1551. event: "session",
  1552. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1553. ): this;
  1554. once(event: "sessionError", listener: (err: Error) => void): this;
  1555. once(
  1556. event: "stream",
  1557. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1558. ): this;
  1559. once(event: "timeout", listener: () => void): this;
  1560. once(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
  1561. once(event: string | symbol, listener: (...args: any[]) => void): this;
  1562. prependListener(
  1563. event: "checkContinue",
  1564. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1565. ): this;
  1566. prependListener(
  1567. event: "request",
  1568. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1569. ): this;
  1570. prependListener(
  1571. event: "session",
  1572. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1573. ): this;
  1574. prependListener(event: "sessionError", listener: (err: Error) => void): this;
  1575. prependListener(
  1576. event: "stream",
  1577. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1578. ): this;
  1579. prependListener(event: "timeout", listener: () => void): this;
  1580. prependListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
  1581. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1582. prependOnceListener(
  1583. event: "checkContinue",
  1584. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1585. ): this;
  1586. prependOnceListener(
  1587. event: "request",
  1588. listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  1589. ): this;
  1590. prependOnceListener(
  1591. event: "session",
  1592. listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
  1593. ): this;
  1594. prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
  1595. prependOnceListener(
  1596. event: "stream",
  1597. listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
  1598. ): this;
  1599. prependOnceListener(event: "timeout", listener: () => void): this;
  1600. prependOnceListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
  1601. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1602. }
  1603. /**
  1604. * A `Http2ServerRequest` object is created by {@link Server} or {@link SecureServer} and passed as the first argument to the `'request'` event. It may be used to access a request status,
  1605. * headers, and
  1606. * data.
  1607. * @since v8.4.0
  1608. */
  1609. export class Http2ServerRequest extends stream.Readable {
  1610. constructor(
  1611. stream: ServerHttp2Stream,
  1612. headers: IncomingHttpHeaders,
  1613. options: stream.ReadableOptions,
  1614. rawHeaders: readonly string[],
  1615. );
  1616. /**
  1617. * The `request.aborted` property will be `true` if the request has
  1618. * been aborted.
  1619. * @since v10.1.0
  1620. */
  1621. readonly aborted: boolean;
  1622. /**
  1623. * The request authority pseudo header field. Because HTTP/2 allows requests
  1624. * to set either `:authority` or `host`, this value is derived from `req.headers[':authority']` if present. Otherwise, it is derived from `req.headers['host']`.
  1625. * @since v8.4.0
  1626. */
  1627. readonly authority: string;
  1628. /**
  1629. * See `request.socket`.
  1630. * @since v8.4.0
  1631. * @deprecated Since v13.0.0 - Use `socket`.
  1632. */
  1633. readonly connection: net.Socket | tls.TLSSocket;
  1634. /**
  1635. * The `request.complete` property will be `true` if the request has
  1636. * been completed, aborted, or destroyed.
  1637. * @since v12.10.0
  1638. */
  1639. readonly complete: boolean;
  1640. /**
  1641. * The request/response headers object.
  1642. *
  1643. * Key-value pairs of header names and values. Header names are lower-cased.
  1644. *
  1645. * ```js
  1646. * // Prints something like:
  1647. * //
  1648. * // { 'user-agent': 'curl/7.22.0',
  1649. * // host: '127.0.0.1:8000',
  1650. * // accept: '*' }
  1651. * console.log(request.headers);
  1652. * ```
  1653. *
  1654. * See `HTTP/2 Headers Object`.
  1655. *
  1656. * In HTTP/2, the request path, host name, protocol, and method are represented as
  1657. * special headers prefixed with the `:` character (e.g. `':path'`). These special
  1658. * headers will be included in the `request.headers` object. Care must be taken not
  1659. * to inadvertently modify these special headers or errors may occur. For instance,
  1660. * removing all headers from the request will cause errors to occur:
  1661. *
  1662. * ```js
  1663. * removeAllHeaders(request.headers);
  1664. * assert(request.url); // Fails because the :path header has been removed
  1665. * ```
  1666. * @since v8.4.0
  1667. */
  1668. readonly headers: IncomingHttpHeaders;
  1669. /**
  1670. * In case of server request, the HTTP version sent by the client. In the case of
  1671. * client response, the HTTP version of the connected-to server. Returns `'2.0'`.
  1672. *
  1673. * Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
  1674. * @since v8.4.0
  1675. */
  1676. readonly httpVersion: string;
  1677. readonly httpVersionMinor: number;
  1678. readonly httpVersionMajor: number;
  1679. /**
  1680. * The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
  1681. * @since v8.4.0
  1682. */
  1683. readonly method: string;
  1684. /**
  1685. * The raw request/response headers list exactly as they were received.
  1686. *
  1687. * The keys and values are in the same list. It is _not_ a
  1688. * list of tuples. So, the even-numbered offsets are key values, and the
  1689. * odd-numbered offsets are the associated values.
  1690. *
  1691. * Header names are not lowercased, and duplicates are not merged.
  1692. *
  1693. * ```js
  1694. * // Prints something like:
  1695. * //
  1696. * // [ 'user-agent',
  1697. * // 'this is invalid because there can be only one',
  1698. * // 'User-Agent',
  1699. * // 'curl/7.22.0',
  1700. * // 'Host',
  1701. * // '127.0.0.1:8000',
  1702. * // 'ACCEPT',
  1703. * // '*' ]
  1704. * console.log(request.rawHeaders);
  1705. * ```
  1706. * @since v8.4.0
  1707. */
  1708. readonly rawHeaders: string[];
  1709. /**
  1710. * The raw request/response trailer keys and values exactly as they were
  1711. * received. Only populated at the `'end'` event.
  1712. * @since v8.4.0
  1713. */
  1714. readonly rawTrailers: string[];
  1715. /**
  1716. * The request scheme pseudo header field indicating the scheme
  1717. * portion of the target URL.
  1718. * @since v8.4.0
  1719. */
  1720. readonly scheme: string;
  1721. /**
  1722. * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
  1723. * applies getters, setters, and methods based on HTTP/2 logic.
  1724. *
  1725. * `destroyed`, `readable`, and `writable` properties will be retrieved from and
  1726. * set on `request.stream`.
  1727. *
  1728. * `destroy`, `emit`, `end`, `on` and `once` methods will be called on `request.stream`.
  1729. *
  1730. * `setTimeout` method will be called on `request.stream.session`.
  1731. *
  1732. * `pause`, `read`, `resume`, and `write` will throw an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
  1733. * more information.
  1734. *
  1735. * All other interactions will be routed directly to the socket. With TLS support,
  1736. * use `request.socket.getPeerCertificate()` to obtain the client's
  1737. * authentication details.
  1738. * @since v8.4.0
  1739. */
  1740. readonly socket: net.Socket | tls.TLSSocket;
  1741. /**
  1742. * The `Http2Stream` object backing the request.
  1743. * @since v8.4.0
  1744. */
  1745. readonly stream: ServerHttp2Stream;
  1746. /**
  1747. * The request/response trailers object. Only populated at the `'end'` event.
  1748. * @since v8.4.0
  1749. */
  1750. readonly trailers: IncomingHttpHeaders;
  1751. /**
  1752. * Request URL string. This contains only the URL that is present in the actual
  1753. * HTTP request. If the request is:
  1754. *
  1755. * ```http
  1756. * GET /status?name=ryan HTTP/1.1
  1757. * Accept: text/plain
  1758. * ```
  1759. *
  1760. * Then `request.url` will be:
  1761. *
  1762. * ```js
  1763. * '/status?name=ryan'
  1764. * ```
  1765. *
  1766. * To parse the url into its parts, `new URL()` can be used:
  1767. *
  1768. * ```console
  1769. * $ node
  1770. * > new URL('/status?name=ryan', 'http://example.com')
  1771. * URL {
  1772. * href: 'http://example.com/status?name=ryan',
  1773. * origin: 'http://example.com',
  1774. * protocol: 'http:',
  1775. * username: '',
  1776. * password: '',
  1777. * host: 'example.com',
  1778. * hostname: 'example.com',
  1779. * port: '',
  1780. * pathname: '/status',
  1781. * search: '?name=ryan',
  1782. * searchParams: URLSearchParams { 'name' => 'ryan' },
  1783. * hash: ''
  1784. * }
  1785. * ```
  1786. * @since v8.4.0
  1787. */
  1788. url: string;
  1789. /**
  1790. * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
  1791. * provided, then it is added as a listener on the `'timeout'` event on
  1792. * the response object.
  1793. *
  1794. * If no `'timeout'` listener is added to the request, the response, or
  1795. * the server, then `Http2Stream`s are destroyed when they time out. If a
  1796. * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
  1797. * @since v8.4.0
  1798. */
  1799. setTimeout(msecs: number, callback?: () => void): void;
  1800. read(size?: number): Buffer | string | null;
  1801. addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
  1802. addListener(event: "close", listener: () => void): this;
  1803. addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  1804. addListener(event: "end", listener: () => void): this;
  1805. addListener(event: "readable", listener: () => void): this;
  1806. addListener(event: "error", listener: (err: Error) => void): this;
  1807. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1808. emit(event: "aborted", hadError: boolean, code: number): boolean;
  1809. emit(event: "close"): boolean;
  1810. emit(event: "data", chunk: Buffer | string): boolean;
  1811. emit(event: "end"): boolean;
  1812. emit(event: "readable"): boolean;
  1813. emit(event: "error", err: Error): boolean;
  1814. emit(event: string | symbol, ...args: any[]): boolean;
  1815. on(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
  1816. on(event: "close", listener: () => void): this;
  1817. on(event: "data", listener: (chunk: Buffer | string) => void): this;
  1818. on(event: "end", listener: () => void): this;
  1819. on(event: "readable", listener: () => void): this;
  1820. on(event: "error", listener: (err: Error) => void): this;
  1821. on(event: string | symbol, listener: (...args: any[]) => void): this;
  1822. once(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
  1823. once(event: "close", listener: () => void): this;
  1824. once(event: "data", listener: (chunk: Buffer | string) => void): this;
  1825. once(event: "end", listener: () => void): this;
  1826. once(event: "readable", listener: () => void): this;
  1827. once(event: "error", listener: (err: Error) => void): this;
  1828. once(event: string | symbol, listener: (...args: any[]) => void): this;
  1829. prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
  1830. prependListener(event: "close", listener: () => void): this;
  1831. prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  1832. prependListener(event: "end", listener: () => void): this;
  1833. prependListener(event: "readable", listener: () => void): this;
  1834. prependListener(event: "error", listener: (err: Error) => void): this;
  1835. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1836. prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
  1837. prependOnceListener(event: "close", listener: () => void): this;
  1838. prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
  1839. prependOnceListener(event: "end", listener: () => void): this;
  1840. prependOnceListener(event: "readable", listener: () => void): this;
  1841. prependOnceListener(event: "error", listener: (err: Error) => void): this;
  1842. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  1843. }
  1844. /**
  1845. * This object is created internally by an HTTP server, not by the user. It is
  1846. * passed as the second parameter to the `'request'` event.
  1847. * @since v8.4.0
  1848. */
  1849. export class Http2ServerResponse<Request extends Http2ServerRequest = Http2ServerRequest> extends stream.Writable {
  1850. constructor(stream: ServerHttp2Stream);
  1851. /**
  1852. * See `response.socket`.
  1853. * @since v8.4.0
  1854. * @deprecated Since v13.0.0 - Use `socket`.
  1855. */
  1856. readonly connection: net.Socket | tls.TLSSocket;
  1857. /**
  1858. * Append a single header value to the header object.
  1859. *
  1860. * If the value is an array, this is equivalent to calling this method multiple times.
  1861. *
  1862. * If there were no previous values for the header, this is equivalent to calling {@link setHeader}.
  1863. *
  1864. * Attempting to set a header field name or value that contains invalid characters will result in a
  1865. * [TypeError](https://nodejs.org/docs/latest-v24.x/api/errors.html#class-typeerror) being thrown.
  1866. *
  1867. * ```js
  1868. * // Returns headers including "set-cookie: a" and "set-cookie: b"
  1869. * const server = http2.createServer((req, res) => {
  1870. * res.setHeader('set-cookie', 'a');
  1871. * res.appendHeader('set-cookie', 'b');
  1872. * res.writeHead(200);
  1873. * res.end('ok');
  1874. * });
  1875. * ```
  1876. * @since v20.12.0
  1877. */
  1878. appendHeader(name: string, value: string | string[]): void;
  1879. /**
  1880. * Boolean value that indicates whether the response has completed. Starts
  1881. * as `false`. After `response.end()` executes, the value will be `true`.
  1882. * @since v8.4.0
  1883. * @deprecated Since v13.4.0,v12.16.0 - Use `writableEnded`.
  1884. */
  1885. readonly finished: boolean;
  1886. /**
  1887. * True if headers were sent, false otherwise (read-only).
  1888. * @since v8.4.0
  1889. */
  1890. readonly headersSent: boolean;
  1891. /**
  1892. * A reference to the original HTTP2 `request` object.
  1893. * @since v15.7.0
  1894. */
  1895. readonly req: Request;
  1896. /**
  1897. * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
  1898. * applies getters, setters, and methods based on HTTP/2 logic.
  1899. *
  1900. * `destroyed`, `readable`, and `writable` properties will be retrieved from and
  1901. * set on `response.stream`.
  1902. *
  1903. * `destroy`, `emit`, `end`, `on` and `once` methods will be called on `response.stream`.
  1904. *
  1905. * `setTimeout` method will be called on `response.stream.session`.
  1906. *
  1907. * `pause`, `read`, `resume`, and `write` will throw an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
  1908. * more information.
  1909. *
  1910. * All other interactions will be routed directly to the socket.
  1911. *
  1912. * ```js
  1913. * import http2 from 'node:http2';
  1914. * const server = http2.createServer((req, res) => {
  1915. * const ip = req.socket.remoteAddress;
  1916. * const port = req.socket.remotePort;
  1917. * res.end(`Your IP address is ${ip} and your source port is ${port}.`);
  1918. * }).listen(3000);
  1919. * ```
  1920. * @since v8.4.0
  1921. */
  1922. readonly socket: net.Socket | tls.TLSSocket;
  1923. /**
  1924. * The `Http2Stream` object backing the response.
  1925. * @since v8.4.0
  1926. */
  1927. readonly stream: ServerHttp2Stream;
  1928. /**
  1929. * When true, the Date header will be automatically generated and sent in
  1930. * the response if it is not already present in the headers. Defaults to true.
  1931. *
  1932. * This should only be disabled for testing; HTTP requires the Date header
  1933. * in responses.
  1934. * @since v8.4.0
  1935. */
  1936. sendDate: boolean;
  1937. /**
  1938. * When using implicit headers (not calling `response.writeHead()` explicitly),
  1939. * this property controls the status code that will be sent to the client when
  1940. * the headers get flushed.
  1941. *
  1942. * ```js
  1943. * response.statusCode = 404;
  1944. * ```
  1945. *
  1946. * After response header was sent to the client, this property indicates the
  1947. * status code which was sent out.
  1948. * @since v8.4.0
  1949. */
  1950. statusCode: number;
  1951. /**
  1952. * Status message is not supported by HTTP/2 (RFC 7540 8.1.2.4). It returns
  1953. * an empty string.
  1954. * @since v8.4.0
  1955. */
  1956. statusMessage: "";
  1957. /**
  1958. * This method adds HTTP trailing headers (a header but at the end of the
  1959. * message) to the response.
  1960. *
  1961. * Attempting to set a header field name or value that contains invalid characters
  1962. * will result in a `TypeError` being thrown.
  1963. * @since v8.4.0
  1964. */
  1965. addTrailers(trailers: OutgoingHttpHeaders): void;
  1966. /**
  1967. * This method signals to the server that all of the response headers and body
  1968. * have been sent; that server should consider this message complete.
  1969. * The method, `response.end()`, MUST be called on each response.
  1970. *
  1971. * If `data` is specified, it is equivalent to calling `response.write(data, encoding)` followed by `response.end(callback)`.
  1972. *
  1973. * If `callback` is specified, it will be called when the response stream
  1974. * is finished.
  1975. * @since v8.4.0
  1976. */
  1977. end(callback?: () => void): this;
  1978. end(data: string | Uint8Array, callback?: () => void): this;
  1979. end(data: string | Uint8Array, encoding: BufferEncoding, callback?: () => void): this;
  1980. /**
  1981. * Reads out a header that has already been queued but not sent to the client.
  1982. * The name is case-insensitive.
  1983. *
  1984. * ```js
  1985. * const contentType = response.getHeader('content-type');
  1986. * ```
  1987. * @since v8.4.0
  1988. */
  1989. getHeader(name: string): string;
  1990. /**
  1991. * Returns an array containing the unique names of the current outgoing headers.
  1992. * All header names are lowercase.
  1993. *
  1994. * ```js
  1995. * response.setHeader('Foo', 'bar');
  1996. * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
  1997. *
  1998. * const headerNames = response.getHeaderNames();
  1999. * // headerNames === ['foo', 'set-cookie']
  2000. * ```
  2001. * @since v8.4.0
  2002. */
  2003. getHeaderNames(): string[];
  2004. /**
  2005. * Returns a shallow copy of the current outgoing headers. Since a shallow copy
  2006. * is used, array values may be mutated without additional calls to various
  2007. * header-related http module methods. The keys of the returned object are the
  2008. * header names and the values are the respective header values. All header names
  2009. * are lowercase.
  2010. *
  2011. * The object returned by the `response.getHeaders()` method _does not_ prototypically inherit from the JavaScript `Object`. This means that typical `Object` methods such as `obj.toString()`,
  2012. * `obj.hasOwnProperty()`, and others
  2013. * are not defined and _will not work_.
  2014. *
  2015. * ```js
  2016. * response.setHeader('Foo', 'bar');
  2017. * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
  2018. *
  2019. * const headers = response.getHeaders();
  2020. * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
  2021. * ```
  2022. * @since v8.4.0
  2023. */
  2024. getHeaders(): OutgoingHttpHeaders;
  2025. /**
  2026. * Returns `true` if the header identified by `name` is currently set in the
  2027. * outgoing headers. The header name matching is case-insensitive.
  2028. *
  2029. * ```js
  2030. * const hasContentType = response.hasHeader('content-type');
  2031. * ```
  2032. * @since v8.4.0
  2033. */
  2034. hasHeader(name: string): boolean;
  2035. /**
  2036. * Removes a header that has been queued for implicit sending.
  2037. *
  2038. * ```js
  2039. * response.removeHeader('Content-Encoding');
  2040. * ```
  2041. * @since v8.4.0
  2042. */
  2043. removeHeader(name: string): void;
  2044. /**
  2045. * Sets a single header value for implicit headers. If this header already exists
  2046. * in the to-be-sent headers, its value will be replaced. Use an array of strings
  2047. * here to send multiple headers with the same name.
  2048. *
  2049. * ```js
  2050. * response.setHeader('Content-Type', 'text/html; charset=utf-8');
  2051. * ```
  2052. *
  2053. * or
  2054. *
  2055. * ```js
  2056. * response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
  2057. * ```
  2058. *
  2059. * Attempting to set a header field name or value that contains invalid characters
  2060. * will result in a `TypeError` being thrown.
  2061. *
  2062. * When headers have been set with `response.setHeader()`, they will be merged
  2063. * with any headers passed to `response.writeHead()`, with the headers passed
  2064. * to `response.writeHead()` given precedence.
  2065. *
  2066. * ```js
  2067. * // Returns content-type = text/plain
  2068. * const server = http2.createServer((req, res) => {
  2069. * res.setHeader('Content-Type', 'text/html; charset=utf-8');
  2070. * res.setHeader('X-Foo', 'bar');
  2071. * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
  2072. * res.end('ok');
  2073. * });
  2074. * ```
  2075. * @since v8.4.0
  2076. */
  2077. setHeader(name: string, value: number | string | readonly string[]): void;
  2078. /**
  2079. * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
  2080. * provided, then it is added as a listener on the `'timeout'` event on
  2081. * the response object.
  2082. *
  2083. * If no `'timeout'` listener is added to the request, the response, or
  2084. * the server, then `Http2Stream` s are destroyed when they time out. If a
  2085. * handler is assigned to the request, the response, or the server's `'timeout'` events, timed out sockets must be handled explicitly.
  2086. * @since v8.4.0
  2087. */
  2088. setTimeout(msecs: number, callback?: () => void): void;
  2089. /**
  2090. * If this method is called and `response.writeHead()` has not been called,
  2091. * it will switch to implicit header mode and flush the implicit headers.
  2092. *
  2093. * This sends a chunk of the response body. This method may
  2094. * be called multiple times to provide successive parts of the body.
  2095. *
  2096. * In the `node:http` module, the response body is omitted when the
  2097. * request is a HEAD request. Similarly, the `204` and `304` responses _must not_ include a message body.
  2098. *
  2099. * `chunk` can be a string or a buffer. If `chunk` is a string,
  2100. * the second parameter specifies how to encode it into a byte stream.
  2101. * By default the `encoding` is `'utf8'`. `callback` will be called when this chunk
  2102. * of data is flushed.
  2103. *
  2104. * This is the raw HTTP body and has nothing to do with higher-level multi-part
  2105. * body encodings that may be used.
  2106. *
  2107. * The first time `response.write()` is called, it will send the buffered
  2108. * header information and the first chunk of the body to the client. The second
  2109. * time `response.write()` is called, Node.js assumes data will be streamed,
  2110. * and sends the new data separately. That is, the response is buffered up to the
  2111. * first chunk of the body.
  2112. *
  2113. * Returns `true` if the entire data was flushed successfully to the kernel
  2114. * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is free again.
  2115. * @since v8.4.0
  2116. */
  2117. write(chunk: string | Uint8Array, callback?: (err: Error) => void): boolean;
  2118. write(chunk: string | Uint8Array, encoding: BufferEncoding, callback?: (err: Error) => void): boolean;
  2119. /**
  2120. * Sends a status `100 Continue` to the client, indicating that the request body
  2121. * should be sent. See the `'checkContinue'` event on `Http2Server` and `Http2SecureServer`.
  2122. * @since v8.4.0
  2123. */
  2124. writeContinue(): void;
  2125. /**
  2126. * Sends a status `103 Early Hints` to the client with a Link header,
  2127. * indicating that the user agent can preload/preconnect the linked resources.
  2128. * The `hints` is an object containing the values of headers to be sent with
  2129. * early hints message.
  2130. *
  2131. * **Example**
  2132. *
  2133. * ```js
  2134. * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
  2135. * response.writeEarlyHints({
  2136. * 'link': earlyHintsLink,
  2137. * });
  2138. *
  2139. * const earlyHintsLinks = [
  2140. * '</styles.css>; rel=preload; as=style',
  2141. * '</scripts.js>; rel=preload; as=script',
  2142. * ];
  2143. * response.writeEarlyHints({
  2144. * 'link': earlyHintsLinks,
  2145. * });
  2146. * ```
  2147. * @since v18.11.0
  2148. */
  2149. writeEarlyHints(hints: Record<string, string | string[]>): void;
  2150. /**
  2151. * Sends a response header to the request. The status code is a 3-digit HTTP
  2152. * status code, like `404`. The last argument, `headers`, are the response headers.
  2153. *
  2154. * Returns a reference to the `Http2ServerResponse`, so that calls can be chained.
  2155. *
  2156. * For compatibility with `HTTP/1`, a human-readable `statusMessage` may be
  2157. * passed as the second argument. However, because the `statusMessage` has no
  2158. * meaning within HTTP/2, the argument will have no effect and a process warning
  2159. * will be emitted.
  2160. *
  2161. * ```js
  2162. * const body = 'hello world';
  2163. * response.writeHead(200, {
  2164. * 'Content-Length': Buffer.byteLength(body),
  2165. * 'Content-Type': 'text/plain; charset=utf-8',
  2166. * });
  2167. * ```
  2168. *
  2169. * `Content-Length` is given in bytes not characters. The`Buffer.byteLength()` API may be used to determine the number of bytes in a
  2170. * given encoding. On outbound messages, Node.js does not check if Content-Length
  2171. * and the length of the body being transmitted are equal or not. However, when
  2172. * receiving messages, Node.js will automatically reject messages when the `Content-Length` does not match the actual payload size.
  2173. *
  2174. * This method may be called at most one time on a message before `response.end()` is called.
  2175. *
  2176. * If `response.write()` or `response.end()` are called before calling
  2177. * this, the implicit/mutable headers will be calculated and call this function.
  2178. *
  2179. * When headers have been set with `response.setHeader()`, they will be merged
  2180. * with any headers passed to `response.writeHead()`, with the headers passed
  2181. * to `response.writeHead()` given precedence.
  2182. *
  2183. * ```js
  2184. * // Returns content-type = text/plain
  2185. * const server = http2.createServer((req, res) => {
  2186. * res.setHeader('Content-Type', 'text/html; charset=utf-8');
  2187. * res.setHeader('X-Foo', 'bar');
  2188. * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
  2189. * res.end('ok');
  2190. * });
  2191. * ```
  2192. *
  2193. * Attempting to set a header field name or value that contains invalid characters
  2194. * will result in a `TypeError` being thrown.
  2195. * @since v8.4.0
  2196. */
  2197. writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
  2198. writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this;
  2199. /**
  2200. * Call `http2stream.pushStream()` with the given headers, and wrap the
  2201. * given `Http2Stream` on a newly created `Http2ServerResponse` as the callback
  2202. * parameter if successful. When `Http2ServerRequest` is closed, the callback is
  2203. * called with an error `ERR_HTTP2_INVALID_STREAM`.
  2204. * @since v8.4.0
  2205. * @param headers An object describing the headers
  2206. * @param callback Called once `http2stream.pushStream()` is finished, or either when the attempt to create the pushed `Http2Stream` has failed or has been rejected, or the state of
  2207. * `Http2ServerRequest` is closed prior to calling the `http2stream.pushStream()` method
  2208. */
  2209. createPushResponse(
  2210. headers: OutgoingHttpHeaders,
  2211. callback: (err: Error | null, res: Http2ServerResponse) => void,
  2212. ): void;
  2213. addListener(event: "close", listener: () => void): this;
  2214. addListener(event: "drain", listener: () => void): this;
  2215. addListener(event: "error", listener: (error: Error) => void): this;
  2216. addListener(event: "finish", listener: () => void): this;
  2217. addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  2218. addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  2219. addListener(event: string | symbol, listener: (...args: any[]) => void): this;
  2220. emit(event: "close"): boolean;
  2221. emit(event: "drain"): boolean;
  2222. emit(event: "error", error: Error): boolean;
  2223. emit(event: "finish"): boolean;
  2224. emit(event: "pipe", src: stream.Readable): boolean;
  2225. emit(event: "unpipe", src: stream.Readable): boolean;
  2226. emit(event: string | symbol, ...args: any[]): boolean;
  2227. on(event: "close", listener: () => void): this;
  2228. on(event: "drain", listener: () => void): this;
  2229. on(event: "error", listener: (error: Error) => void): this;
  2230. on(event: "finish", listener: () => void): this;
  2231. on(event: "pipe", listener: (src: stream.Readable) => void): this;
  2232. on(event: "unpipe", listener: (src: stream.Readable) => void): this;
  2233. on(event: string | symbol, listener: (...args: any[]) => void): this;
  2234. once(event: "close", listener: () => void): this;
  2235. once(event: "drain", listener: () => void): this;
  2236. once(event: "error", listener: (error: Error) => void): this;
  2237. once(event: "finish", listener: () => void): this;
  2238. once(event: "pipe", listener: (src: stream.Readable) => void): this;
  2239. once(event: "unpipe", listener: (src: stream.Readable) => void): this;
  2240. once(event: string | symbol, listener: (...args: any[]) => void): this;
  2241. prependListener(event: "close", listener: () => void): this;
  2242. prependListener(event: "drain", listener: () => void): this;
  2243. prependListener(event: "error", listener: (error: Error) => void): this;
  2244. prependListener(event: "finish", listener: () => void): this;
  2245. prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  2246. prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  2247. prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
  2248. prependOnceListener(event: "close", listener: () => void): this;
  2249. prependOnceListener(event: "drain", listener: () => void): this;
  2250. prependOnceListener(event: "error", listener: (error: Error) => void): this;
  2251. prependOnceListener(event: "finish", listener: () => void): this;
  2252. prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
  2253. prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
  2254. prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
  2255. }
  2256. export namespace constants {
  2257. const NGHTTP2_SESSION_SERVER: number;
  2258. const NGHTTP2_SESSION_CLIENT: number;
  2259. const NGHTTP2_STREAM_STATE_IDLE: number;
  2260. const NGHTTP2_STREAM_STATE_OPEN: number;
  2261. const NGHTTP2_STREAM_STATE_RESERVED_LOCAL: number;
  2262. const NGHTTP2_STREAM_STATE_RESERVED_REMOTE: number;
  2263. const NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL: number;
  2264. const NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE: number;
  2265. const NGHTTP2_STREAM_STATE_CLOSED: number;
  2266. const NGHTTP2_NO_ERROR: number;
  2267. const NGHTTP2_PROTOCOL_ERROR: number;
  2268. const NGHTTP2_INTERNAL_ERROR: number;
  2269. const NGHTTP2_FLOW_CONTROL_ERROR: number;
  2270. const NGHTTP2_SETTINGS_TIMEOUT: number;
  2271. const NGHTTP2_STREAM_CLOSED: number;
  2272. const NGHTTP2_FRAME_SIZE_ERROR: number;
  2273. const NGHTTP2_REFUSED_STREAM: number;
  2274. const NGHTTP2_CANCEL: number;
  2275. const NGHTTP2_COMPRESSION_ERROR: number;
  2276. const NGHTTP2_CONNECT_ERROR: number;
  2277. const NGHTTP2_ENHANCE_YOUR_CALM: number;
  2278. const NGHTTP2_INADEQUATE_SECURITY: number;
  2279. const NGHTTP2_HTTP_1_1_REQUIRED: number;
  2280. const NGHTTP2_ERR_FRAME_SIZE_ERROR: number;
  2281. const NGHTTP2_FLAG_NONE: number;
  2282. const NGHTTP2_FLAG_END_STREAM: number;
  2283. const NGHTTP2_FLAG_END_HEADERS: number;
  2284. const NGHTTP2_FLAG_ACK: number;
  2285. const NGHTTP2_FLAG_PADDED: number;
  2286. const NGHTTP2_FLAG_PRIORITY: number;
  2287. const DEFAULT_SETTINGS_HEADER_TABLE_SIZE: number;
  2288. const DEFAULT_SETTINGS_ENABLE_PUSH: number;
  2289. const DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: number;
  2290. const DEFAULT_SETTINGS_MAX_FRAME_SIZE: number;
  2291. const MAX_MAX_FRAME_SIZE: number;
  2292. const MIN_MAX_FRAME_SIZE: number;
  2293. const MAX_INITIAL_WINDOW_SIZE: number;
  2294. const NGHTTP2_DEFAULT_WEIGHT: number;
  2295. const NGHTTP2_SETTINGS_HEADER_TABLE_SIZE: number;
  2296. const NGHTTP2_SETTINGS_ENABLE_PUSH: number;
  2297. const NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS: number;
  2298. const NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE: number;
  2299. const NGHTTP2_SETTINGS_MAX_FRAME_SIZE: number;
  2300. const NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE: number;
  2301. const PADDING_STRATEGY_NONE: number;
  2302. const PADDING_STRATEGY_MAX: number;
  2303. const PADDING_STRATEGY_CALLBACK: number;
  2304. const HTTP2_HEADER_STATUS: string;
  2305. const HTTP2_HEADER_METHOD: string;
  2306. const HTTP2_HEADER_AUTHORITY: string;
  2307. const HTTP2_HEADER_SCHEME: string;
  2308. const HTTP2_HEADER_PATH: string;
  2309. const HTTP2_HEADER_ACCEPT_CHARSET: string;
  2310. const HTTP2_HEADER_ACCEPT_ENCODING: string;
  2311. const HTTP2_HEADER_ACCEPT_LANGUAGE: string;
  2312. const HTTP2_HEADER_ACCEPT_RANGES: string;
  2313. const HTTP2_HEADER_ACCEPT: string;
  2314. const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS: string;
  2315. const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS: string;
  2316. const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS: string;
  2317. const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN: string;
  2318. const HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS: string;
  2319. const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS: string;
  2320. const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD: string;
  2321. const HTTP2_HEADER_AGE: string;
  2322. const HTTP2_HEADER_ALLOW: string;
  2323. const HTTP2_HEADER_AUTHORIZATION: string;
  2324. const HTTP2_HEADER_CACHE_CONTROL: string;
  2325. const HTTP2_HEADER_CONNECTION: string;
  2326. const HTTP2_HEADER_CONTENT_DISPOSITION: string;
  2327. const HTTP2_HEADER_CONTENT_ENCODING: string;
  2328. const HTTP2_HEADER_CONTENT_LANGUAGE: string;
  2329. const HTTP2_HEADER_CONTENT_LENGTH: string;
  2330. const HTTP2_HEADER_CONTENT_LOCATION: string;
  2331. const HTTP2_HEADER_CONTENT_MD5: string;
  2332. const HTTP2_HEADER_CONTENT_RANGE: string;
  2333. const HTTP2_HEADER_CONTENT_TYPE: string;
  2334. const HTTP2_HEADER_COOKIE: string;
  2335. const HTTP2_HEADER_DATE: string;
  2336. const HTTP2_HEADER_ETAG: string;
  2337. const HTTP2_HEADER_EXPECT: string;
  2338. const HTTP2_HEADER_EXPIRES: string;
  2339. const HTTP2_HEADER_FROM: string;
  2340. const HTTP2_HEADER_HOST: string;
  2341. const HTTP2_HEADER_IF_MATCH: string;
  2342. const HTTP2_HEADER_IF_MODIFIED_SINCE: string;
  2343. const HTTP2_HEADER_IF_NONE_MATCH: string;
  2344. const HTTP2_HEADER_IF_RANGE: string;
  2345. const HTTP2_HEADER_IF_UNMODIFIED_SINCE: string;
  2346. const HTTP2_HEADER_LAST_MODIFIED: string;
  2347. const HTTP2_HEADER_LINK: string;
  2348. const HTTP2_HEADER_LOCATION: string;
  2349. const HTTP2_HEADER_MAX_FORWARDS: string;
  2350. const HTTP2_HEADER_PREFER: string;
  2351. const HTTP2_HEADER_PROXY_AUTHENTICATE: string;
  2352. const HTTP2_HEADER_PROXY_AUTHORIZATION: string;
  2353. const HTTP2_HEADER_RANGE: string;
  2354. const HTTP2_HEADER_REFERER: string;
  2355. const HTTP2_HEADER_REFRESH: string;
  2356. const HTTP2_HEADER_RETRY_AFTER: string;
  2357. const HTTP2_HEADER_SERVER: string;
  2358. const HTTP2_HEADER_SET_COOKIE: string;
  2359. const HTTP2_HEADER_STRICT_TRANSPORT_SECURITY: string;
  2360. const HTTP2_HEADER_TRANSFER_ENCODING: string;
  2361. const HTTP2_HEADER_TE: string;
  2362. const HTTP2_HEADER_UPGRADE: string;
  2363. const HTTP2_HEADER_USER_AGENT: string;
  2364. const HTTP2_HEADER_VARY: string;
  2365. const HTTP2_HEADER_VIA: string;
  2366. const HTTP2_HEADER_WWW_AUTHENTICATE: string;
  2367. const HTTP2_HEADER_HTTP2_SETTINGS: string;
  2368. const HTTP2_HEADER_KEEP_ALIVE: string;
  2369. const HTTP2_HEADER_PROXY_CONNECTION: string;
  2370. const HTTP2_METHOD_ACL: string;
  2371. const HTTP2_METHOD_BASELINE_CONTROL: string;
  2372. const HTTP2_METHOD_BIND: string;
  2373. const HTTP2_METHOD_CHECKIN: string;
  2374. const HTTP2_METHOD_CHECKOUT: string;
  2375. const HTTP2_METHOD_CONNECT: string;
  2376. const HTTP2_METHOD_COPY: string;
  2377. const HTTP2_METHOD_DELETE: string;
  2378. const HTTP2_METHOD_GET: string;
  2379. const HTTP2_METHOD_HEAD: string;
  2380. const HTTP2_METHOD_LABEL: string;
  2381. const HTTP2_METHOD_LINK: string;
  2382. const HTTP2_METHOD_LOCK: string;
  2383. const HTTP2_METHOD_MERGE: string;
  2384. const HTTP2_METHOD_MKACTIVITY: string;
  2385. const HTTP2_METHOD_MKCALENDAR: string;
  2386. const HTTP2_METHOD_MKCOL: string;
  2387. const HTTP2_METHOD_MKREDIRECTREF: string;
  2388. const HTTP2_METHOD_MKWORKSPACE: string;
  2389. const HTTP2_METHOD_MOVE: string;
  2390. const HTTP2_METHOD_OPTIONS: string;
  2391. const HTTP2_METHOD_ORDERPATCH: string;
  2392. const HTTP2_METHOD_PATCH: string;
  2393. const HTTP2_METHOD_POST: string;
  2394. const HTTP2_METHOD_PRI: string;
  2395. const HTTP2_METHOD_PROPFIND: string;
  2396. const HTTP2_METHOD_PROPPATCH: string;
  2397. const HTTP2_METHOD_PUT: string;
  2398. const HTTP2_METHOD_REBIND: string;
  2399. const HTTP2_METHOD_REPORT: string;
  2400. const HTTP2_METHOD_SEARCH: string;
  2401. const HTTP2_METHOD_TRACE: string;
  2402. const HTTP2_METHOD_UNBIND: string;
  2403. const HTTP2_METHOD_UNCHECKOUT: string;
  2404. const HTTP2_METHOD_UNLINK: string;
  2405. const HTTP2_METHOD_UNLOCK: string;
  2406. const HTTP2_METHOD_UPDATE: string;
  2407. const HTTP2_METHOD_UPDATEREDIRECTREF: string;
  2408. const HTTP2_METHOD_VERSION_CONTROL: string;
  2409. const HTTP_STATUS_CONTINUE: number;
  2410. const HTTP_STATUS_SWITCHING_PROTOCOLS: number;
  2411. const HTTP_STATUS_PROCESSING: number;
  2412. const HTTP_STATUS_OK: number;
  2413. const HTTP_STATUS_CREATED: number;
  2414. const HTTP_STATUS_ACCEPTED: number;
  2415. const HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION: number;
  2416. const HTTP_STATUS_NO_CONTENT: number;
  2417. const HTTP_STATUS_RESET_CONTENT: number;
  2418. const HTTP_STATUS_PARTIAL_CONTENT: number;
  2419. const HTTP_STATUS_MULTI_STATUS: number;
  2420. const HTTP_STATUS_ALREADY_REPORTED: number;
  2421. const HTTP_STATUS_IM_USED: number;
  2422. const HTTP_STATUS_MULTIPLE_CHOICES: number;
  2423. const HTTP_STATUS_MOVED_PERMANENTLY: number;
  2424. const HTTP_STATUS_FOUND: number;
  2425. const HTTP_STATUS_SEE_OTHER: number;
  2426. const HTTP_STATUS_NOT_MODIFIED: number;
  2427. const HTTP_STATUS_USE_PROXY: number;
  2428. const HTTP_STATUS_TEMPORARY_REDIRECT: number;
  2429. const HTTP_STATUS_PERMANENT_REDIRECT: number;
  2430. const HTTP_STATUS_BAD_REQUEST: number;
  2431. const HTTP_STATUS_UNAUTHORIZED: number;
  2432. const HTTP_STATUS_PAYMENT_REQUIRED: number;
  2433. const HTTP_STATUS_FORBIDDEN: number;
  2434. const HTTP_STATUS_NOT_FOUND: number;
  2435. const HTTP_STATUS_METHOD_NOT_ALLOWED: number;
  2436. const HTTP_STATUS_NOT_ACCEPTABLE: number;
  2437. const HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED: number;
  2438. const HTTP_STATUS_REQUEST_TIMEOUT: number;
  2439. const HTTP_STATUS_CONFLICT: number;
  2440. const HTTP_STATUS_GONE: number;
  2441. const HTTP_STATUS_LENGTH_REQUIRED: number;
  2442. const HTTP_STATUS_PRECONDITION_FAILED: number;
  2443. const HTTP_STATUS_PAYLOAD_TOO_LARGE: number;
  2444. const HTTP_STATUS_URI_TOO_LONG: number;
  2445. const HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE: number;
  2446. const HTTP_STATUS_RANGE_NOT_SATISFIABLE: number;
  2447. const HTTP_STATUS_EXPECTATION_FAILED: number;
  2448. const HTTP_STATUS_TEAPOT: number;
  2449. const HTTP_STATUS_MISDIRECTED_REQUEST: number;
  2450. const HTTP_STATUS_UNPROCESSABLE_ENTITY: number;
  2451. const HTTP_STATUS_LOCKED: number;
  2452. const HTTP_STATUS_FAILED_DEPENDENCY: number;
  2453. const HTTP_STATUS_UNORDERED_COLLECTION: number;
  2454. const HTTP_STATUS_UPGRADE_REQUIRED: number;
  2455. const HTTP_STATUS_PRECONDITION_REQUIRED: number;
  2456. const HTTP_STATUS_TOO_MANY_REQUESTS: number;
  2457. const HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE: number;
  2458. const HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS: number;
  2459. const HTTP_STATUS_INTERNAL_SERVER_ERROR: number;
  2460. const HTTP_STATUS_NOT_IMPLEMENTED: number;
  2461. const HTTP_STATUS_BAD_GATEWAY: number;
  2462. const HTTP_STATUS_SERVICE_UNAVAILABLE: number;
  2463. const HTTP_STATUS_GATEWAY_TIMEOUT: number;
  2464. const HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED: number;
  2465. const HTTP_STATUS_VARIANT_ALSO_NEGOTIATES: number;
  2466. const HTTP_STATUS_INSUFFICIENT_STORAGE: number;
  2467. const HTTP_STATUS_LOOP_DETECTED: number;
  2468. const HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED: number;
  2469. const HTTP_STATUS_NOT_EXTENDED: number;
  2470. const HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED: number;
  2471. }
  2472. /**
  2473. * This symbol can be set as a property on the HTTP/2 headers object with
  2474. * an array value in order to provide a list of headers considered sensitive.
  2475. */
  2476. export const sensitiveHeaders: symbol;
  2477. /**
  2478. * Returns an object containing the default settings for an `Http2Session` instance. This method returns a new object instance every time it is called
  2479. * so instances returned may be safely modified for use.
  2480. * @since v8.4.0
  2481. */
  2482. export function getDefaultSettings(): Settings;
  2483. /**
  2484. * Returns a `Buffer` instance containing serialized representation of the given
  2485. * HTTP/2 settings as specified in the [HTTP/2](https://tools.ietf.org/html/rfc7540) specification. This is intended
  2486. * for use with the `HTTP2-Settings` header field.
  2487. *
  2488. * ```js
  2489. * import http2 from 'node:http2';
  2490. *
  2491. * const packed = http2.getPackedSettings({ enablePush: false });
  2492. *
  2493. * console.log(packed.toString('base64'));
  2494. * // Prints: AAIAAAAA
  2495. * ```
  2496. * @since v8.4.0
  2497. */
  2498. export function getPackedSettings(settings: Settings): Buffer;
  2499. /**
  2500. * Returns a `HTTP/2 Settings Object` containing the deserialized settings from
  2501. * the given `Buffer` as generated by `http2.getPackedSettings()`.
  2502. * @since v8.4.0
  2503. * @param buf The packed settings.
  2504. */
  2505. export function getUnpackedSettings(buf: Uint8Array): Settings;
  2506. /**
  2507. * Returns a `net.Server` instance that creates and manages `Http2Session` instances.
  2508. *
  2509. * Since there are no browsers known that support [unencrypted HTTP/2](https://http2.github.io/faq/#does-http2-require-encryption), the use of {@link createSecureServer} is necessary when
  2510. * communicating
  2511. * with browser clients.
  2512. *
  2513. * ```js
  2514. * import http2 from 'node:http2';
  2515. *
  2516. * // Create an unencrypted HTTP/2 server.
  2517. * // Since there are no browsers known that support
  2518. * // unencrypted HTTP/2, the use of `http2.createSecureServer()`
  2519. * // is necessary when communicating with browser clients.
  2520. * const server = http2.createServer();
  2521. *
  2522. * server.on('stream', (stream, headers) => {
  2523. * stream.respond({
  2524. * 'content-type': 'text/html; charset=utf-8',
  2525. * ':status': 200,
  2526. * });
  2527. * stream.end('<h1>Hello World</h1>');
  2528. * });
  2529. *
  2530. * server.listen(8000);
  2531. * ```
  2532. * @since v8.4.0
  2533. * @param onRequestHandler See `Compatibility API`
  2534. */
  2535. export function createServer(
  2536. onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
  2537. ): Http2Server;
  2538. export function createServer<
  2539. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  2540. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  2541. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  2542. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  2543. >(
  2544. options: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
  2545. onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  2546. ): Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>;
  2547. /**
  2548. * Returns a `tls.Server` instance that creates and manages `Http2Session` instances.
  2549. *
  2550. * ```js
  2551. * import http2 from 'node:http2';
  2552. * import fs from 'node:fs';
  2553. *
  2554. * const options = {
  2555. * key: fs.readFileSync('server-key.pem'),
  2556. * cert: fs.readFileSync('server-cert.pem'),
  2557. * };
  2558. *
  2559. * // Create a secure HTTP/2 server
  2560. * const server = http2.createSecureServer(options);
  2561. *
  2562. * server.on('stream', (stream, headers) => {
  2563. * stream.respond({
  2564. * 'content-type': 'text/html; charset=utf-8',
  2565. * ':status': 200,
  2566. * });
  2567. * stream.end('<h1>Hello World</h1>');
  2568. * });
  2569. *
  2570. * server.listen(8443);
  2571. * ```
  2572. * @since v8.4.0
  2573. * @param onRequestHandler See `Compatibility API`
  2574. */
  2575. export function createSecureServer(
  2576. onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
  2577. ): Http2SecureServer;
  2578. export function createSecureServer<
  2579. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  2580. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  2581. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  2582. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  2583. >(
  2584. options: SecureServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
  2585. onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
  2586. ): Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
  2587. /**
  2588. * Returns a `ClientHttp2Session` instance.
  2589. *
  2590. * ```js
  2591. * import http2 from 'node:http2';
  2592. * const client = http2.connect('https://localhost:1234');
  2593. *
  2594. * // Use the client
  2595. *
  2596. * client.close();
  2597. * ```
  2598. * @since v8.4.0
  2599. * @param authority The remote HTTP/2 server to connect to. This must be in the form of a minimal, valid URL with the `http://` or `https://` prefix, host name, and IP port (if a non-default port
  2600. * is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
  2601. * @param listener Will be registered as a one-time listener of the {@link 'connect'} event.
  2602. */
  2603. export function connect(
  2604. authority: string | url.URL,
  2605. listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  2606. ): ClientHttp2Session;
  2607. export function connect(
  2608. authority: string | url.URL,
  2609. options?: ClientSessionOptions | SecureClientSessionOptions,
  2610. listener?: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
  2611. ): ClientHttp2Session;
  2612. /**
  2613. * Create an HTTP/2 server session from an existing socket.
  2614. * @param socket A Duplex Stream
  2615. * @param options Any `{@link createServer}` options can be provided.
  2616. * @since v20.12.0
  2617. */
  2618. export function performServerHandshake<
  2619. Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
  2620. Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
  2621. Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
  2622. Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
  2623. >(
  2624. socket: stream.Duplex,
  2625. options?: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
  2626. ): ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>;
  2627. }
  2628. declare module "node:http2" {
  2629. export * from "http2";
  2630. }