@encharm/cws 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/dist/bindings/cws_linux_108.node +0 -0
  2. package/dist/bindings/cws_linux_64.node +0 -0
  3. package/dist/bindings/cws_linux_72.node +0 -0
  4. package/dist/bindings/cws_linux_79.node +0 -0
  5. package/dist/bindings/cws_linux_83.node +0 -0
  6. package/dist/bindings/cws_linux_93.node +0 -0
  7. package/dist/bindings/cws_win32_64.node +0 -0
  8. package/dist/bindings/cws_win32_72.node +0 -0
  9. package/dist/bindings/cws_win32_79.node +0 -0
  10. package/dist/bindings/cws_win32_83.node +0 -0
  11. package/dist/bindings/cws_win32_93.node +0 -0
  12. package/package.json +1 -1
  13. package/src/Addon.h +24 -2
  14. package/src/HTTPSocket.cpp +1 -1
  15. package/src/headers/{13 → 18}/aliased_buffer.h +61 -9
  16. package/src/headers/18/aliased_struct-inl.h +54 -0
  17. package/src/headers/18/aliased_struct.h +63 -0
  18. package/src/headers/{12 → 18}/async_wrap-inl.h +0 -0
  19. package/src/headers/{12 → 18}/async_wrap.h +26 -2
  20. package/src/headers/{12/base64.h → 18/base64-inl.h} +78 -86
  21. package/src/headers/18/base64.h +69 -0
  22. package/src/headers/{12 → 18}/base_object-inl.h +46 -25
  23. package/src/headers/{12 → 18}/base_object.h +82 -17
  24. package/src/headers/{12 → 18}/callback_queue-inl.h +9 -9
  25. package/src/headers/{12 → 18}/callback_queue.h +13 -5
  26. package/src/headers/18/cares_wrap.h +523 -0
  27. package/src/headers/{12 → 18}/connect_wrap.h +0 -0
  28. package/src/headers/{12 → 18}/connection_wrap.h +0 -0
  29. package/src/headers/18/crypto/crypto_aes.h +89 -0
  30. package/src/headers/{13/node_crypto_bio.h → 18/crypto/crypto_bio.h} +3 -4
  31. package/src/headers/18/crypto/crypto_cipher.h +291 -0
  32. package/src/headers/{13/node_crypto_clienthello-inl.h → 18/crypto/crypto_clienthello-inl.h} +4 -5
  33. package/src/headers/{13/node_crypto_clienthello.h → 18/crypto/crypto_clienthello.h} +3 -4
  34. package/src/headers/{12/node_crypto_common.h → 18/crypto/crypto_common.h} +49 -36
  35. package/src/headers/18/crypto/crypto_context.h +147 -0
  36. package/src/headers/18/crypto/crypto_dh.h +156 -0
  37. package/src/headers/18/crypto/crypto_dsa.h +77 -0
  38. package/src/headers/18/crypto/crypto_ec.h +170 -0
  39. package/src/headers/{12/node_crypto_groups.h → 18/crypto/crypto_groups.h} +3 -3
  40. package/src/headers/18/crypto/crypto_hash.h +89 -0
  41. package/src/headers/18/crypto/crypto_hkdf.h +65 -0
  42. package/src/headers/18/crypto/crypto_hmac.h +94 -0
  43. package/src/headers/18/crypto/crypto_keygen.h +305 -0
  44. package/src/headers/18/crypto/crypto_keys.h +420 -0
  45. package/src/headers/18/crypto/crypto_pbkdf2.h +76 -0
  46. package/src/headers/18/crypto/crypto_random.h +130 -0
  47. package/src/headers/18/crypto/crypto_rsa.h +141 -0
  48. package/src/headers/18/crypto/crypto_scrypt.h +87 -0
  49. package/src/headers/18/crypto/crypto_sig.h +168 -0
  50. package/src/headers/18/crypto/crypto_spkac.h +21 -0
  51. package/src/headers/18/crypto/crypto_timing.h +20 -0
  52. package/src/headers/{13/tls_wrap.h → 18/crypto/crypto_tls.h} +137 -66
  53. package/src/headers/18/crypto/crypto_util.h +791 -0
  54. package/src/headers/18/crypto/crypto_x509.h +143 -0
  55. package/src/headers/{12 → 18}/debug_utils-inl.h +0 -0
  56. package/src/headers/{13 → 18}/debug_utils.h +7 -4
  57. package/src/headers/{12 → 18}/diagnosticfilename-inl.h +0 -0
  58. package/src/headers/{12 → 18}/env-inl.h +397 -304
  59. package/src/headers/{12 → 18}/env.h +397 -172
  60. package/src/headers/{12 → 18}/handle_wrap.h +7 -3
  61. package/src/headers/18/histogram-inl.h +107 -0
  62. package/src/headers/18/histogram.h +239 -0
  63. package/src/headers/{13 → 18}/inspector_agent.h +4 -7
  64. package/src/headers/{12 → 18}/inspector_io.h +0 -0
  65. package/src/headers/{13 → 18}/inspector_profiler.h +17 -5
  66. package/src/headers/{12 → 18}/inspector_socket.h +0 -0
  67. package/src/headers/{12 → 18}/inspector_socket_server.h +0 -0
  68. package/src/headers/18/js_native_api.h +571 -0
  69. package/src/headers/{13 → 18}/js_native_api_types.h +30 -7
  70. package/src/headers/{12 → 18}/js_native_api_v8.h +220 -83
  71. package/src/headers/{12 → 18}/js_native_api_v8_internals.h +6 -5
  72. package/src/headers/{12 → 18}/js_stream.h +0 -0
  73. package/src/headers/{12 → 18}/json_utils.h +0 -0
  74. package/src/headers/{13 → 18}/memory_tracker-inl.h +6 -5
  75. package/src/headers/{13 → 18}/memory_tracker.h +0 -7
  76. package/src/headers/{13 → 18}/module_wrap.h +24 -7
  77. package/src/headers/{13 → 18}/node.h +329 -68
  78. package/src/headers/18/node_api.h +288 -0
  79. package/src/headers/18/node_api_internals.h +38 -0
  80. package/src/headers/{12 → 18}/node_api_types.h +12 -9
  81. package/src/headers/{12 → 18}/node_binding.h +0 -0
  82. package/src/headers/18/node_blob.h +191 -0
  83. package/src/headers/18/node_bob-inl.h +37 -0
  84. package/src/headers/18/node_bob.h +111 -0
  85. package/src/headers/{13 → 18}/node_buffer.h +0 -0
  86. package/src/headers/{13 → 18}/node_constants.h +5 -1
  87. package/src/headers/{12 → 18}/node_context_data.h +5 -0
  88. package/src/headers/{12 → 18}/node_contextify.h +37 -2
  89. package/src/headers/{10/node_win32_perfctr_provider.h → 18/node_crypto.h} +30 -31
  90. package/src/headers/{12 → 18}/node_dir.h +0 -0
  91. package/src/headers/{12 → 18}/node_dtrace.h +0 -0
  92. package/src/headers/{12 → 18}/node_errors.h +90 -24
  93. package/src/headers/18/node_external_reference.h +145 -0
  94. package/src/headers/{13 → 18}/node_file-inl.h +38 -21
  95. package/src/headers/{12 → 18}/node_file.h +74 -13
  96. package/src/headers/{13 → 18}/node_http2.h +365 -269
  97. package/src/headers/{12 → 18}/node_http2_state.h +40 -50
  98. package/src/headers/{13 → 18}/node_http_common-inl.h +25 -5
  99. package/src/headers/{13 → 18}/node_http_common.h +24 -20
  100. package/src/headers/{13 → 18}/node_i18n.h +2 -1
  101. package/src/headers/{12 → 18}/node_internals.h +39 -41
  102. package/src/headers/{13 → 18}/node_main_instance.h +15 -18
  103. package/src/headers/{12 → 18}/node_mem-inl.h +0 -0
  104. package/src/headers/{12 → 18}/node_mem.h +1 -1
  105. package/src/headers/{13 → 18}/node_messaging.h +170 -23
  106. package/src/headers/{12 → 18}/node_metadata.h +17 -4
  107. package/src/headers/{12 → 18}/node_mutex.h +77 -1
  108. package/src/headers/{12 → 18}/node_native_module.h +11 -1
  109. package/src/headers/{13 → 18}/node_native_module_env.h +14 -8
  110. package/src/headers/{12 → 18}/node_object_wrap.h +0 -0
  111. package/src/headers/{13 → 18}/node_options-inl.h +51 -21
  112. package/src/headers/{13 → 18}/node_options.h +46 -14
  113. package/src/headers/18/node_perf.h +168 -0
  114. package/src/headers/{12 → 18}/node_perf_common.h +16 -22
  115. package/src/headers/{12 → 18}/node_platform.h +21 -16
  116. package/src/headers/18/node_process-inl.h +26 -0
  117. package/src/headers/18/node_process.h +97 -0
  118. package/src/headers/{13 → 18}/node_report.h +2 -2
  119. package/src/headers/{13 → 18}/node_revert.h +10 -0
  120. package/src/headers/{12 → 18}/node_root_certs.h +439 -651
  121. package/src/headers/18/node_snapshot_builder.h +43 -0
  122. package/src/headers/18/node_snapshotable.h +130 -0
  123. package/src/headers/{12 → 18}/node_sockaddr-inl.h +100 -4
  124. package/src/headers/18/node_sockaddr.h +405 -0
  125. package/src/headers/{12 → 18}/node_stat_watcher.h +7 -1
  126. package/src/headers/{12 → 18}/node_union_bytes.h +0 -0
  127. package/src/headers/{13 → 18}/node_url.h +18 -1
  128. package/src/headers/18/node_v8.h +41 -0
  129. package/src/headers/{12 → 18}/node_v8_platform-inl.h +10 -0
  130. package/src/headers/{13 → 18}/node_version.h +7 -7
  131. package/src/headers/{12 → 18}/node_wasi.h +0 -0
  132. package/src/headers/18/node_wasm_web_api.h +55 -0
  133. package/src/headers/{13 → 18}/node_watchdog.h +0 -0
  134. package/src/headers/{10 → 18}/node_win32_etw_provider-inl.h +7 -6
  135. package/src/headers/{10 → 18}/node_win32_etw_provider.h +0 -0
  136. package/src/headers/{13 → 18}/node_worker.h +24 -17
  137. package/src/headers/{12 → 18}/pipe_wrap.h +2 -0
  138. package/src/headers/{12 → 18}/req_wrap-inl.h +0 -0
  139. package/src/headers/{12 → 18}/req_wrap.h +1 -1
  140. package/src/headers/{12 → 18}/spawn_sync.h +0 -0
  141. package/src/headers/{13 → 18}/stream_base-inl.h +58 -22
  142. package/src/headers/{13 → 18}/stream_base.h +29 -3
  143. package/src/headers/{13 → 18}/stream_pipe.h +8 -3
  144. package/src/headers/{12 → 18}/stream_wrap.h +4 -1
  145. package/src/headers/{13 → 18}/string_bytes.h +0 -7
  146. package/src/headers/{12 → 18}/string_decoder-inl.h +0 -0
  147. package/src/headers/{10 → 18}/string_decoder.h +0 -0
  148. package/src/headers/{13 → 18}/string_search.h +2 -2
  149. package/src/headers/{12 → 18}/tcp_wrap.h +4 -0
  150. package/src/headers/{12 → 18}/threadpoolwork-inl.h +0 -0
  151. package/src/headers/18/timer_wrap-inl.h +32 -0
  152. package/src/headers/18/timer_wrap.h +85 -0
  153. package/src/headers/{13 → 18}/tracing/agent.h +1 -1
  154. package/src/headers/{12 → 18}/tracing/node_trace_buffer.h +0 -0
  155. package/src/headers/{12 → 18}/tracing/node_trace_writer.h +0 -0
  156. package/src/headers/{13 → 18}/tracing/trace_event.h +23 -13
  157. package/src/headers/{12 → 18}/tracing/trace_event_common.h +0 -0
  158. package/src/headers/{12 → 18}/tracing/traced_value.h +0 -0
  159. package/src/headers/{13 → 18}/tty_wrap.h +2 -1
  160. package/src/headers/{13 → 18}/udp_wrap.h +5 -0
  161. package/src/headers/{13 → 18}/util-inl.h +69 -15
  162. package/src/headers/{13 → 18}/util.h +93 -31
  163. package/src/headers/18/v8-fast-api-calls.h +939 -0
  164. package/src/headers/{12 → 18}/v8abbr.h +2 -2
  165. package/src/headers/10/aliased_buffer.h +0 -241
  166. package/src/headers/10/async_wrap-inl.h +0 -106
  167. package/src/headers/10/async_wrap.h +0 -218
  168. package/src/headers/10/base64.h +0 -197
  169. package/src/headers/10/base_object-inl.h +0 -132
  170. package/src/headers/10/base_object.h +0 -115
  171. package/src/headers/10/connect_wrap.h +0 -28
  172. package/src/headers/10/connection_wrap.h +0 -30
  173. package/src/headers/10/debug_utils.h +0 -128
  174. package/src/headers/10/env-inl.h +0 -906
  175. package/src/headers/10/env.h +0 -1046
  176. package/src/headers/10/handle_wrap.h +0 -114
  177. package/src/headers/10/inspector_agent.h +0 -137
  178. package/src/headers/10/inspector_io.h +0 -97
  179. package/src/headers/10/inspector_socket.h +0 -59
  180. package/src/headers/10/inspector_socket_server.h +0 -104
  181. package/src/headers/10/js_stream.h +0 -57
  182. package/src/headers/10/memory_tracker-inl.h +0 -318
  183. package/src/headers/10/memory_tracker.h +0 -246
  184. package/src/headers/10/module_wrap.h +0 -100
  185. package/src/headers/10/node.h +0 -863
  186. package/src/headers/10/node_api.h +0 -752
  187. package/src/headers/10/node_api_types.h +0 -171
  188. package/src/headers/10/node_buffer.h +0 -90
  189. package/src/headers/10/node_code_cache.h +0 -17
  190. package/src/headers/10/node_constants.h +0 -74
  191. package/src/headers/10/node_context_data.h +0 -39
  192. package/src/headers/10/node_contextify.h +0 -141
  193. package/src/headers/10/node_counters.h +0 -59
  194. package/src/headers/10/node_crypto.h +0 -699
  195. package/src/headers/10/node_crypto_bio.h +0 -177
  196. package/src/headers/10/node_crypto_clienthello-inl.h +0 -92
  197. package/src/headers/10/node_crypto_clienthello.h +0 -131
  198. package/src/headers/10/node_crypto_groups.h +0 -416
  199. package/src/headers/10/node_dtrace.h +0 -84
  200. package/src/headers/10/node_errors.h +0 -118
  201. package/src/headers/10/node_file.h +0 -373
  202. package/src/headers/10/node_http2.h +0 -1304
  203. package/src/headers/10/node_http2_state.h +0 -158
  204. package/src/headers/10/node_i18n.h +0 -69
  205. package/src/headers/10/node_internals.h +0 -952
  206. package/src/headers/10/node_javascript.h +0 -41
  207. package/src/headers/10/node_messaging.h +0 -219
  208. package/src/headers/10/node_mutex.h +0 -191
  209. package/src/headers/10/node_object_wrap.h +0 -130
  210. package/src/headers/10/node_options-inl.h +0 -444
  211. package/src/headers/10/node_options.h +0 -397
  212. package/src/headers/10/node_perf.h +0 -134
  213. package/src/headers/10/node_perf_common.h +0 -96
  214. package/src/headers/10/node_persistent.h +0 -30
  215. package/src/headers/10/node_platform.h +0 -170
  216. package/src/headers/10/node_revert.h +0 -75
  217. package/src/headers/10/node_root_certs.h +0 -3393
  218. package/src/headers/10/node_stat_watcher.h +0 -65
  219. package/src/headers/10/node_url.h +0 -193
  220. package/src/headers/10/node_version.h +0 -120
  221. package/src/headers/10/node_watchdog.h +0 -114
  222. package/src/headers/10/node_worker.h +0 -94
  223. package/src/headers/10/pipe_wrap.h +0 -76
  224. package/src/headers/10/req_wrap-inl.h +0 -166
  225. package/src/headers/10/req_wrap.h +0 -61
  226. package/src/headers/10/sharedarraybuffer_metadata.h +0 -67
  227. package/src/headers/10/spawn_sync.h +0 -240
  228. package/src/headers/10/stream_base-inl.h +0 -458
  229. package/src/headers/10/stream_base.h +0 -378
  230. package/src/headers/10/stream_pipe.h +0 -72
  231. package/src/headers/10/stream_wrap.h +0 -130
  232. package/src/headers/10/string_bytes.h +0 -126
  233. package/src/headers/10/string_decoder-inl.h +0 -38
  234. package/src/headers/10/string_search.h +0 -620
  235. package/src/headers/10/tcp_wrap.h +0 -99
  236. package/src/headers/10/tls_wrap.h +0 -195
  237. package/src/headers/10/tracing/agent.h +0 -178
  238. package/src/headers/10/tracing/node_trace_buffer.h +0 -83
  239. package/src/headers/10/tracing/node_trace_writer.h +0 -75
  240. package/src/headers/10/tracing/trace_event.h +0 -706
  241. package/src/headers/10/tracing/trace_event_common.h +0 -1102
  242. package/src/headers/10/tracing/traced_value.h +0 -68
  243. package/src/headers/10/tty_wrap.h +0 -63
  244. package/src/headers/10/udp_wrap.h +0 -102
  245. package/src/headers/10/util-inl.h +0 -459
  246. package/src/headers/10/util.h +0 -508
  247. package/src/headers/10/v8abbr.h +0 -121
  248. package/src/headers/12/aliased_buffer.h +0 -263
  249. package/src/headers/12/debug_utils.h +0 -181
  250. package/src/headers/12/histogram-inl.h +0 -83
  251. package/src/headers/12/histogram.h +0 -98
  252. package/src/headers/12/http_parser_adaptor.h +0 -24
  253. package/src/headers/12/inspector_agent.h +0 -147
  254. package/src/headers/12/inspector_profiler.h +0 -137
  255. package/src/headers/12/js_native_api.h +0 -541
  256. package/src/headers/12/js_native_api_types.h +0 -139
  257. package/src/headers/12/memory_tracker-inl.h +0 -339
  258. package/src/headers/12/memory_tracker.h +0 -283
  259. package/src/headers/12/module_wrap.h +0 -99
  260. package/src/headers/12/node.h +0 -887
  261. package/src/headers/12/node_api.h +0 -239
  262. package/src/headers/12/node_buffer.h +0 -92
  263. package/src/headers/12/node_constants.h +0 -80
  264. package/src/headers/12/node_crypto.h +0 -800
  265. package/src/headers/12/node_crypto_bio.h +0 -195
  266. package/src/headers/12/node_crypto_clienthello-inl.h +0 -91
  267. package/src/headers/12/node_crypto_clienthello.h +0 -132
  268. package/src/headers/12/node_file-inl.h +0 -289
  269. package/src/headers/12/node_http2.h +0 -1311
  270. package/src/headers/12/node_http_parser_impl.h +0 -994
  271. package/src/headers/12/node_i18n.h +0 -144
  272. package/src/headers/12/node_main_instance.h +0 -97
  273. package/src/headers/12/node_messaging.h +0 -227
  274. package/src/headers/12/node_native_module_env.h +0 -65
  275. package/src/headers/12/node_options-inl.h +0 -447
  276. package/src/headers/12/node_options.h +0 -479
  277. package/src/headers/12/node_perf.h +0 -181
  278. package/src/headers/12/node_process.h +0 -41
  279. package/src/headers/12/node_report.h +0 -47
  280. package/src/headers/12/node_revert.h +0 -78
  281. package/src/headers/12/node_sockaddr.h +0 -123
  282. package/src/headers/12/node_url.h +0 -188
  283. package/src/headers/12/node_version.h +0 -98
  284. package/src/headers/12/node_watchdog.h +0 -152
  285. package/src/headers/12/node_win32_etw_provider-inl.h +0 -287
  286. package/src/headers/12/node_win32_etw_provider.h +0 -99
  287. package/src/headers/12/node_worker.h +0 -142
  288. package/src/headers/12/sharedarraybuffer_metadata.h +0 -72
  289. package/src/headers/12/stream_base-inl.h +0 -323
  290. package/src/headers/12/stream_base.h +0 -431
  291. package/src/headers/12/stream_pipe.h +0 -72
  292. package/src/headers/12/string_bytes.h +0 -142
  293. package/src/headers/12/string_decoder.h +0 -50
  294. package/src/headers/12/string_search.h +0 -638
  295. package/src/headers/12/tls_wrap.h +0 -221
  296. package/src/headers/12/tracing/agent.h +0 -195
  297. package/src/headers/12/tracing/trace_event.h +0 -710
  298. package/src/headers/12/tty_wrap.h +0 -64
  299. package/src/headers/12/udp_wrap.h +0 -222
  300. package/src/headers/12/util-inl.h +0 -529
  301. package/src/headers/12/util.h +0 -765
  302. package/src/headers/13/async_wrap-inl.h +0 -94
  303. package/src/headers/13/async_wrap.h +0 -224
  304. package/src/headers/13/base64.h +0 -197
  305. package/src/headers/13/base_object-inl.h +0 -353
  306. package/src/headers/13/base_object.h +0 -229
  307. package/src/headers/13/connect_wrap.h +0 -26
  308. package/src/headers/13/connection_wrap.h +0 -30
  309. package/src/headers/13/debug_utils-inl.h +0 -223
  310. package/src/headers/13/diagnosticfilename-inl.h +0 -33
  311. package/src/headers/13/env-inl.h +0 -1293
  312. package/src/headers/13/env.h +0 -1469
  313. package/src/headers/13/handle_wrap.h +0 -117
  314. package/src/headers/13/histogram-inl.h +0 -83
  315. package/src/headers/13/histogram.h +0 -98
  316. package/src/headers/13/inspector_io.h +0 -78
  317. package/src/headers/13/inspector_socket.h +0 -60
  318. package/src/headers/13/inspector_socket_server.h +0 -110
  319. package/src/headers/13/js_native_api.h +0 -541
  320. package/src/headers/13/js_native_api_v8.h +0 -303
  321. package/src/headers/13/js_native_api_v8_internals.h +0 -38
  322. package/src/headers/13/js_stream.h +0 -52
  323. package/src/headers/13/json_utils.h +0 -160
  324. package/src/headers/13/node_api.h +0 -239
  325. package/src/headers/13/node_api_types.h +0 -44
  326. package/src/headers/13/node_binding.h +0 -99
  327. package/src/headers/13/node_context_data.h +0 -39
  328. package/src/headers/13/node_contextify.h +0 -161
  329. package/src/headers/13/node_crypto.h +0 -800
  330. package/src/headers/13/node_crypto_common.h +0 -138
  331. package/src/headers/13/node_crypto_groups.h +0 -415
  332. package/src/headers/13/node_dir.h +0 -52
  333. package/src/headers/13/node_dtrace.h +0 -86
  334. package/src/headers/13/node_errors.h +0 -210
  335. package/src/headers/13/node_file.h +0 -364
  336. package/src/headers/13/node_http2_state.h +0 -144
  337. package/src/headers/13/node_internals.h +0 -405
  338. package/src/headers/13/node_mem-inl.h +0 -112
  339. package/src/headers/13/node_mem.h +0 -41
  340. package/src/headers/13/node_metadata.h +0 -109
  341. package/src/headers/13/node_mutex.h +0 -247
  342. package/src/headers/13/node_native_module.h +0 -99
  343. package/src/headers/13/node_object_wrap.h +0 -132
  344. package/src/headers/13/node_perf.h +0 -181
  345. package/src/headers/13/node_perf_common.h +0 -97
  346. package/src/headers/13/node_platform.h +0 -190
  347. package/src/headers/13/node_process.h +0 -41
  348. package/src/headers/13/node_root_certs.h +0 -3424
  349. package/src/headers/13/node_sockaddr-inl.h +0 -170
  350. package/src/headers/13/node_sockaddr.h +0 -123
  351. package/src/headers/13/node_stat_watcher.h +0 -66
  352. package/src/headers/13/node_union_bytes.h +0 -103
  353. package/src/headers/13/node_v8_platform-inl.h +0 -184
  354. package/src/headers/13/node_wasi.h +0 -108
  355. package/src/headers/13/node_win32_etw_provider-inl.h +0 -287
  356. package/src/headers/13/node_win32_etw_provider.h +0 -99
  357. package/src/headers/13/pipe_wrap.h +0 -78
  358. package/src/headers/13/req_wrap-inl.h +0 -170
  359. package/src/headers/13/req_wrap.h +0 -77
  360. package/src/headers/13/spawn_sync.h +0 -242
  361. package/src/headers/13/stream_wrap.h +0 -130
  362. package/src/headers/13/string_decoder-inl.h +0 -37
  363. package/src/headers/13/string_decoder.h +0 -50
  364. package/src/headers/13/tcp_wrap.h +0 -101
  365. package/src/headers/13/threadpoolwork-inl.h +0 -57
  366. package/src/headers/13/tracing/node_trace_buffer.h +0 -83
  367. package/src/headers/13/tracing/node_trace_writer.h +0 -75
  368. package/src/headers/13/tracing/trace_event_common.h +0 -1109
  369. package/src/headers/13/tracing/traced_value.h +0 -70
  370. package/src/headers/13/v8abbr.h +0 -124
@@ -1,1304 +0,0 @@
1
- #ifndef SRC_NODE_HTTP2_H_
2
- #define SRC_NODE_HTTP2_H_
3
-
4
- #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
-
6
- #include "nghttp2/nghttp2.h"
7
- #include "node_http2_state.h"
8
- #include "node_perf.h"
9
- #include "stream_base-inl.h"
10
- #include "string_bytes.h"
11
-
12
- #include <algorithm>
13
- #include <queue>
14
-
15
- namespace node {
16
- namespace http2 {
17
-
18
- using v8::Array;
19
- using v8::Context;
20
- using v8::Isolate;
21
- using v8::MaybeLocal;
22
-
23
- using performance::PerformanceEntry;
24
-
25
- // We strictly limit the number of outstanding unacknowledged PINGS a user
26
- // may send in order to prevent abuse. The current default cap is 10. The
27
- // user may set a different limit using a per Http2Session configuration
28
- // option.
29
- #define DEFAULT_MAX_PINGS 10
30
-
31
- // Also strictly limit the number of outstanding SETTINGS frames a user sends
32
- #define DEFAULT_MAX_SETTINGS 10
33
-
34
- // Default maximum total memory cap for Http2Session.
35
- #define DEFAULT_MAX_SESSION_MEMORY 1e7;
36
-
37
- // These are the standard HTTP/2 defaults as specified by the RFC
38
- #define DEFAULT_SETTINGS_HEADER_TABLE_SIZE 4096
39
- #define DEFAULT_SETTINGS_ENABLE_PUSH 1
40
- #define DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE 65535
41
- #define DEFAULT_SETTINGS_MAX_FRAME_SIZE 16384
42
- #define DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE 65535
43
- #define MAX_MAX_FRAME_SIZE 16777215
44
- #define MIN_MAX_FRAME_SIZE DEFAULT_SETTINGS_MAX_FRAME_SIZE
45
- #define MAX_INITIAL_WINDOW_SIZE 2147483647
46
-
47
- #define MAX_MAX_HEADER_LIST_SIZE 16777215u
48
- #define DEFAULT_MAX_HEADER_LIST_PAIRS 128u
49
-
50
- #define MAX_BUFFER_COUNT 16
51
-
52
- enum nghttp2_session_type {
53
- NGHTTP2_SESSION_SERVER,
54
- NGHTTP2_SESSION_CLIENT
55
- };
56
-
57
- enum nghttp2_stream_flags {
58
- NGHTTP2_STREAM_FLAG_NONE = 0x0,
59
- // Writable side has ended
60
- NGHTTP2_STREAM_FLAG_SHUT = 0x1,
61
- // Reading has started
62
- NGHTTP2_STREAM_FLAG_READ_START = 0x2,
63
- // Reading is paused
64
- NGHTTP2_STREAM_FLAG_READ_PAUSED = 0x4,
65
- // Stream is closed
66
- NGHTTP2_STREAM_FLAG_CLOSED = 0x8,
67
- // Stream is destroyed
68
- NGHTTP2_STREAM_FLAG_DESTROYED = 0x10,
69
- // Stream has trailers
70
- NGHTTP2_STREAM_FLAG_TRAILERS = 0x20,
71
- // Stream has received all the data it can
72
- NGHTTP2_STREAM_FLAG_EOS = 0x40
73
- };
74
-
75
- enum nghttp2_stream_options {
76
- // Stream is not going to have any DATA frames
77
- STREAM_OPTION_EMPTY_PAYLOAD = 0x1,
78
- // Stream might have trailing headers
79
- STREAM_OPTION_GET_TRAILERS = 0x2,
80
- };
81
-
82
- struct nghttp2_stream_write : public MemoryRetainer {
83
- WriteWrap* req_wrap = nullptr;
84
- uv_buf_t buf;
85
-
86
- inline explicit nghttp2_stream_write(uv_buf_t buf_) : buf(buf_) {}
87
- inline nghttp2_stream_write(WriteWrap* req, uv_buf_t buf_) :
88
- req_wrap(req), buf(buf_) {}
89
-
90
- void MemoryInfo(MemoryTracker* tracker) const override;
91
- SET_MEMORY_INFO_NAME(nghttp2_stream_write)
92
- SET_SELF_SIZE(nghttp2_stream_write)
93
- };
94
-
95
- struct nghttp2_header : public MemoryRetainer {
96
- nghttp2_rcbuf* name = nullptr;
97
- nghttp2_rcbuf* value = nullptr;
98
- uint8_t flags = 0;
99
-
100
- void MemoryInfo(MemoryTracker* tracker) const override;
101
- SET_MEMORY_INFO_NAME(nghttp2_header)
102
- SET_SELF_SIZE(nghttp2_header)
103
- };
104
-
105
-
106
- // Unlike the HTTP/1 implementation, the HTTP/2 implementation is not limited
107
- // to a fixed number of known supported HTTP methods. These constants, therefore
108
- // are provided strictly as a convenience to users and are exposed via the
109
- // require('http2').constants object.
110
- #define HTTP_KNOWN_METHODS(V) \
111
- V(ACL, "ACL") \
112
- V(BASELINE_CONTROL, "BASELINE-CONTROL") \
113
- V(BIND, "BIND") \
114
- V(CHECKIN, "CHECKIN") \
115
- V(CHECKOUT, "CHECKOUT") \
116
- V(CONNECT, "CONNECT") \
117
- V(COPY, "COPY") \
118
- V(DELETE, "DELETE") \
119
- V(GET, "GET") \
120
- V(HEAD, "HEAD") \
121
- V(LABEL, "LABEL") \
122
- V(LINK, "LINK") \
123
- V(LOCK, "LOCK") \
124
- V(MERGE, "MERGE") \
125
- V(MKACTIVITY, "MKACTIVITY") \
126
- V(MKCALENDAR, "MKCALENDAR") \
127
- V(MKCOL, "MKCOL") \
128
- V(MKREDIRECTREF, "MKREDIRECTREF") \
129
- V(MKWORKSPACE, "MKWORKSPACE") \
130
- V(MOVE, "MOVE") \
131
- V(OPTIONS, "OPTIONS") \
132
- V(ORDERPATCH, "ORDERPATCH") \
133
- V(PATCH, "PATCH") \
134
- V(POST, "POST") \
135
- V(PRI, "PRI") \
136
- V(PROPFIND, "PROPFIND") \
137
- V(PROPPATCH, "PROPPATCH") \
138
- V(PUT, "PUT") \
139
- V(REBIND, "REBIND") \
140
- V(REPORT, "REPORT") \
141
- V(SEARCH, "SEARCH") \
142
- V(TRACE, "TRACE") \
143
- V(UNBIND, "UNBIND") \
144
- V(UNCHECKOUT, "UNCHECKOUT") \
145
- V(UNLINK, "UNLINK") \
146
- V(UNLOCK, "UNLOCK") \
147
- V(UPDATE, "UPDATE") \
148
- V(UPDATEREDIRECTREF, "UPDATEREDIRECTREF") \
149
- V(VERSION_CONTROL, "VERSION-CONTROL")
150
-
151
- // These are provided strictly as a convenience to users and are exposed via the
152
- // require('http2').constants objects
153
- #define HTTP_KNOWN_HEADERS(V) \
154
- V(STATUS, ":status") \
155
- V(METHOD, ":method") \
156
- V(AUTHORITY, ":authority") \
157
- V(SCHEME, ":scheme") \
158
- V(PATH, ":path") \
159
- V(PROTOCOL, ":protocol") \
160
- V(ACCEPT_CHARSET, "accept-charset") \
161
- V(ACCEPT_ENCODING, "accept-encoding") \
162
- V(ACCEPT_LANGUAGE, "accept-language") \
163
- V(ACCEPT_RANGES, "accept-ranges") \
164
- V(ACCEPT, "accept") \
165
- V(ACCESS_CONTROL_ALLOW_CREDENTIALS, "access-control-allow-credentials") \
166
- V(ACCESS_CONTROL_ALLOW_HEADERS, "access-control-allow-headers") \
167
- V(ACCESS_CONTROL_ALLOW_METHODS, "access-control-allow-methods") \
168
- V(ACCESS_CONTROL_ALLOW_ORIGIN, "access-control-allow-origin") \
169
- V(ACCESS_CONTROL_EXPOSE_HEADERS, "access-control-expose-headers") \
170
- V(ACCESS_CONTROL_MAX_AGE, "access-control-max-age") \
171
- V(ACCESS_CONTROL_REQUEST_HEADERS, "access-control-request-headers") \
172
- V(ACCESS_CONTROL_REQUEST_METHOD, "access-control-request-method") \
173
- V(AGE, "age") \
174
- V(ALLOW, "allow") \
175
- V(AUTHORIZATION, "authorization") \
176
- V(CACHE_CONTROL, "cache-control") \
177
- V(CONNECTION, "connection") \
178
- V(CONTENT_DISPOSITION, "content-disposition") \
179
- V(CONTENT_ENCODING, "content-encoding") \
180
- V(CONTENT_LANGUAGE, "content-language") \
181
- V(CONTENT_LENGTH, "content-length") \
182
- V(CONTENT_LOCATION, "content-location") \
183
- V(CONTENT_MD5, "content-md5") \
184
- V(CONTENT_RANGE, "content-range") \
185
- V(CONTENT_TYPE, "content-type") \
186
- V(COOKIE, "cookie") \
187
- V(DATE, "date") \
188
- V(DNT, "dnt") \
189
- V(ETAG, "etag") \
190
- V(EXPECT, "expect") \
191
- V(EXPIRES, "expires") \
192
- V(FORWARDED, "forwarded") \
193
- V(FROM, "from") \
194
- V(HOST, "host") \
195
- V(IF_MATCH, "if-match") \
196
- V(IF_MODIFIED_SINCE, "if-modified-since") \
197
- V(IF_NONE_MATCH, "if-none-match") \
198
- V(IF_RANGE, "if-range") \
199
- V(IF_UNMODIFIED_SINCE, "if-unmodified-since") \
200
- V(LAST_MODIFIED, "last-modified") \
201
- V(LINK, "link") \
202
- V(LOCATION, "location") \
203
- V(MAX_FORWARDS, "max-forwards") \
204
- V(PREFER, "prefer") \
205
- V(PROXY_AUTHENTICATE, "proxy-authenticate") \
206
- V(PROXY_AUTHORIZATION, "proxy-authorization") \
207
- V(RANGE, "range") \
208
- V(REFERER, "referer") \
209
- V(REFRESH, "refresh") \
210
- V(RETRY_AFTER, "retry-after") \
211
- V(SERVER, "server") \
212
- V(SET_COOKIE, "set-cookie") \
213
- V(STRICT_TRANSPORT_SECURITY, "strict-transport-security") \
214
- V(TRAILER, "trailer") \
215
- V(TRANSFER_ENCODING, "transfer-encoding") \
216
- V(TE, "te") \
217
- V(TK, "tk") \
218
- V(UPGRADE_INSECURE_REQUESTS, "upgrade-insecure-requests") \
219
- V(UPGRADE, "upgrade") \
220
- V(USER_AGENT, "user-agent") \
221
- V(VARY, "vary") \
222
- V(VIA, "via") \
223
- V(WARNING, "warning") \
224
- V(WWW_AUTHENTICATE, "www-authenticate") \
225
- V(X_CONTENT_TYPE_OPTIONS, "x-content-type-options") \
226
- V(X_FRAME_OPTIONS, "x-frame-options") \
227
- V(HTTP2_SETTINGS, "http2-settings") \
228
- V(KEEP_ALIVE, "keep-alive") \
229
- V(PROXY_CONNECTION, "proxy-connection")
230
-
231
- enum http_known_headers {
232
- HTTP_KNOWN_HEADER_MIN,
233
- #define V(name, value) HTTP_HEADER_##name,
234
- HTTP_KNOWN_HEADERS(V)
235
- #undef V
236
- HTTP_KNOWN_HEADER_MAX
237
- };
238
-
239
- // While some of these codes are used within the HTTP/2 implementation in
240
- // core, they are provided strictly as a convenience to users and are exposed
241
- // via the require('http2').constants object.
242
- #define HTTP_STATUS_CODES(V) \
243
- V(CONTINUE, 100) \
244
- V(SWITCHING_PROTOCOLS, 101) \
245
- V(PROCESSING, 102) \
246
- V(EARLY_HINTS, 103) \
247
- V(OK, 200) \
248
- V(CREATED, 201) \
249
- V(ACCEPTED, 202) \
250
- V(NON_AUTHORITATIVE_INFORMATION, 203) \
251
- V(NO_CONTENT, 204) \
252
- V(RESET_CONTENT, 205) \
253
- V(PARTIAL_CONTENT, 206) \
254
- V(MULTI_STATUS, 207) \
255
- V(ALREADY_REPORTED, 208) \
256
- V(IM_USED, 226) \
257
- V(MULTIPLE_CHOICES, 300) \
258
- V(MOVED_PERMANENTLY, 301) \
259
- V(FOUND, 302) \
260
- V(SEE_OTHER, 303) \
261
- V(NOT_MODIFIED, 304) \
262
- V(USE_PROXY, 305) \
263
- V(TEMPORARY_REDIRECT, 307) \
264
- V(PERMANENT_REDIRECT, 308) \
265
- V(BAD_REQUEST, 400) \
266
- V(UNAUTHORIZED, 401) \
267
- V(PAYMENT_REQUIRED, 402) \
268
- V(FORBIDDEN, 403) \
269
- V(NOT_FOUND, 404) \
270
- V(METHOD_NOT_ALLOWED, 405) \
271
- V(NOT_ACCEPTABLE, 406) \
272
- V(PROXY_AUTHENTICATION_REQUIRED, 407) \
273
- V(REQUEST_TIMEOUT, 408) \
274
- V(CONFLICT, 409) \
275
- V(GONE, 410) \
276
- V(LENGTH_REQUIRED, 411) \
277
- V(PRECONDITION_FAILED, 412) \
278
- V(PAYLOAD_TOO_LARGE, 413) \
279
- V(URI_TOO_LONG, 414) \
280
- V(UNSUPPORTED_MEDIA_TYPE, 415) \
281
- V(RANGE_NOT_SATISFIABLE, 416) \
282
- V(EXPECTATION_FAILED, 417) \
283
- V(TEAPOT, 418) \
284
- V(MISDIRECTED_REQUEST, 421) \
285
- V(UNPROCESSABLE_ENTITY, 422) \
286
- V(LOCKED, 423) \
287
- V(FAILED_DEPENDENCY, 424) \
288
- V(UNORDERED_COLLECTION, 425) \
289
- V(UPGRADE_REQUIRED, 426) \
290
- V(PRECONDITION_REQUIRED, 428) \
291
- V(TOO_MANY_REQUESTS, 429) \
292
- V(REQUEST_HEADER_FIELDS_TOO_LARGE, 431) \
293
- V(UNAVAILABLE_FOR_LEGAL_REASONS, 451) \
294
- V(INTERNAL_SERVER_ERROR, 500) \
295
- V(NOT_IMPLEMENTED, 501) \
296
- V(BAD_GATEWAY, 502) \
297
- V(SERVICE_UNAVAILABLE, 503) \
298
- V(GATEWAY_TIMEOUT, 504) \
299
- V(HTTP_VERSION_NOT_SUPPORTED, 505) \
300
- V(VARIANT_ALSO_NEGOTIATES, 506) \
301
- V(INSUFFICIENT_STORAGE, 507) \
302
- V(LOOP_DETECTED, 508) \
303
- V(BANDWIDTH_LIMIT_EXCEEDED, 509) \
304
- V(NOT_EXTENDED, 510) \
305
- V(NETWORK_AUTHENTICATION_REQUIRED, 511)
306
-
307
- enum http_status_codes {
308
- #define V(name, code) HTTP_STATUS_##name = code,
309
- HTTP_STATUS_CODES(V)
310
- #undef V
311
- };
312
-
313
- // The Padding Strategy determines the method by which extra padding is
314
- // selected for HEADERS and DATA frames. These are configurable via the
315
- // options passed in to a Http2Session object.
316
- enum padding_strategy_type {
317
- // No padding strategy. This is the default.
318
- PADDING_STRATEGY_NONE,
319
- // Attempts to ensure that the frame is 8-byte aligned
320
- PADDING_STRATEGY_ALIGNED,
321
- // Padding will ensure all data frames are maxFrameSize
322
- PADDING_STRATEGY_MAX,
323
- // Padding will be determined via a JS callback. Note that this can be
324
- // expensive because the callback is called once for every DATA and
325
- // HEADERS frame. For performance reasons, this strategy should be
326
- // avoided.
327
- PADDING_STRATEGY_CALLBACK
328
- };
329
-
330
- enum session_state_flags {
331
- SESSION_STATE_NONE = 0x0,
332
- SESSION_STATE_HAS_SCOPE = 0x1,
333
- SESSION_STATE_WRITE_SCHEDULED = 0x2,
334
- SESSION_STATE_CLOSED = 0x4,
335
- SESSION_STATE_CLOSING = 0x8,
336
- SESSION_STATE_SENDING = 0x10,
337
- SESSION_STATE_WRITE_IN_PROGRESS = 0x20,
338
- SESSION_STATE_READING_STOPPED = 0x40,
339
- SESSION_STATE_NGHTTP2_RECV_PAUSED = 0x80
340
- };
341
-
342
- typedef uint32_t(*get_setting)(nghttp2_session* session,
343
- nghttp2_settings_id id);
344
-
345
- class Http2Session;
346
- class Http2Stream;
347
-
348
- // This scope should be present when any call into nghttp2 that may schedule
349
- // data to be written to the underlying transport is made, and schedules
350
- // such a write automatically once the scope is exited.
351
- class Http2Scope {
352
- public:
353
- explicit Http2Scope(Http2Stream* stream);
354
- explicit Http2Scope(Http2Session* session);
355
- ~Http2Scope();
356
-
357
- private:
358
- Http2Session* session_ = nullptr;
359
- Local<Object> session_handle_;
360
- };
361
-
362
- // The Http2Options class is used to parse the options object passed in to
363
- // a Http2Session object and convert those into an appropriate nghttp2_option
364
- // struct. This is the primary mechanism by which the Http2Session object is
365
- // configured.
366
- class Http2Options {
367
- public:
368
- Http2Options(Environment* env, nghttp2_session_type type);
369
-
370
- ~Http2Options() {
371
- nghttp2_option_del(options_);
372
- }
373
-
374
- nghttp2_option* operator*() const {
375
- return options_;
376
- }
377
-
378
- void SetMaxHeaderPairs(uint32_t max) {
379
- max_header_pairs_ = max;
380
- }
381
-
382
- uint32_t GetMaxHeaderPairs() const {
383
- return max_header_pairs_;
384
- }
385
-
386
- void SetPaddingStrategy(padding_strategy_type val) {
387
- padding_strategy_ = static_cast<padding_strategy_type>(val);
388
- }
389
-
390
- padding_strategy_type GetPaddingStrategy() const {
391
- return padding_strategy_;
392
- }
393
-
394
- void SetMaxOutstandingPings(size_t max) {
395
- max_outstanding_pings_ = max;
396
- }
397
-
398
- size_t GetMaxOutstandingPings() {
399
- return max_outstanding_pings_;
400
- }
401
-
402
- void SetMaxOutstandingSettings(size_t max) {
403
- max_outstanding_settings_ = max;
404
- }
405
-
406
- size_t GetMaxOutstandingSettings() {
407
- return max_outstanding_settings_;
408
- }
409
-
410
- void SetMaxSessionMemory(uint64_t max) {
411
- max_session_memory_ = max;
412
- }
413
-
414
- uint64_t GetMaxSessionMemory() {
415
- return max_session_memory_;
416
- }
417
-
418
- private:
419
- nghttp2_option* options_;
420
- uint64_t max_session_memory_ = DEFAULT_MAX_SESSION_MEMORY;
421
- uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
422
- padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
423
- size_t max_outstanding_pings_ = DEFAULT_MAX_PINGS;
424
- size_t max_outstanding_settings_ = DEFAULT_MAX_SETTINGS;
425
- };
426
-
427
- class Http2Priority {
428
- public:
429
- Http2Priority(Environment* env,
430
- Local<Value> parent,
431
- Local<Value> weight,
432
- Local<Value> exclusive);
433
-
434
- nghttp2_priority_spec* operator*() {
435
- return &spec;
436
- }
437
- private:
438
- nghttp2_priority_spec spec;
439
- };
440
-
441
- class Http2StreamListener : public StreamListener {
442
- public:
443
- uv_buf_t OnStreamAlloc(size_t suggested_size) override;
444
- void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
445
- };
446
-
447
- class Http2Stream : public AsyncWrap,
448
- public StreamBase {
449
- public:
450
- static Http2Stream* New(
451
- Http2Session* session,
452
- int32_t id,
453
- nghttp2_headers_category category = NGHTTP2_HCAT_HEADERS,
454
- int options = 0);
455
- ~Http2Stream() override;
456
-
457
- nghttp2_stream* operator*();
458
-
459
- Http2Session* session() { return session_; }
460
- const Http2Session* session() const { return session_; }
461
-
462
- void EmitStatistics();
463
-
464
- // Process a Data Chunk
465
- void OnDataChunk(uv_buf_t* chunk);
466
-
467
-
468
- // Required for StreamBase
469
- int ReadStart() override;
470
-
471
- // Required for StreamBase
472
- int ReadStop() override;
473
-
474
- // Required for StreamBase
475
- int DoShutdown(ShutdownWrap* req_wrap) override;
476
-
477
- bool HasWantsWrite() const override { return true; }
478
-
479
- // Initiate a response on this stream.
480
- int SubmitResponse(nghttp2_nv* nva, size_t len, int options);
481
-
482
- // Submit informational headers for this stream
483
- int SubmitInfo(nghttp2_nv* nva, size_t len);
484
-
485
- // Submit trailing headers for this stream
486
- int SubmitTrailers(nghttp2_nv* nva, size_t len);
487
- void OnTrailers();
488
-
489
- // Submit a PRIORITY frame for this stream
490
- int SubmitPriority(nghttp2_priority_spec* prispec, bool silent = false);
491
-
492
- // Submits an RST_STREAM frame using the given code
493
- void SubmitRstStream(const uint32_t code);
494
-
495
- void FlushRstStream();
496
-
497
- // Submits a PUSH_PROMISE frame with this stream as the parent.
498
- Http2Stream* SubmitPushPromise(
499
- nghttp2_nv* nva,
500
- size_t len,
501
- int32_t* ret,
502
- int options = 0);
503
-
504
-
505
- void Close(int32_t code);
506
-
507
- // Destroy this stream instance and free all held memory.
508
- void Destroy();
509
-
510
- inline bool IsDestroyed() const {
511
- return flags_ & NGHTTP2_STREAM_FLAG_DESTROYED;
512
- }
513
-
514
- inline bool IsWritable() const {
515
- return !(flags_ & NGHTTP2_STREAM_FLAG_SHUT);
516
- }
517
-
518
- inline bool IsPaused() const {
519
- return flags_ & NGHTTP2_STREAM_FLAG_READ_PAUSED;
520
- }
521
-
522
- inline bool IsClosed() const {
523
- return flags_ & NGHTTP2_STREAM_FLAG_CLOSED;
524
- }
525
-
526
- inline bool HasTrailers() const {
527
- return flags_ & NGHTTP2_STREAM_FLAG_TRAILERS;
528
- }
529
-
530
- // Returns true if this stream is in the reading state, which occurs when
531
- // the NGHTTP2_STREAM_FLAG_READ_START flag has been set and the
532
- // NGHTTP2_STREAM_FLAG_READ_PAUSED flag is *not* set.
533
- inline bool IsReading() const {
534
- return flags_ & NGHTTP2_STREAM_FLAG_READ_START &&
535
- !(flags_ & NGHTTP2_STREAM_FLAG_READ_PAUSED);
536
- }
537
-
538
- // Returns the RST_STREAM code used to close this stream
539
- inline int32_t code() const { return code_; }
540
-
541
- // Returns the stream identifier for this stream
542
- inline int32_t id() const { return id_; }
543
-
544
- inline void IncrementAvailableOutboundLength(size_t amount);
545
- inline void DecrementAvailableOutboundLength(size_t amount);
546
-
547
- bool AddHeader(nghttp2_rcbuf* name, nghttp2_rcbuf* value, uint8_t flags);
548
-
549
- inline std::vector<nghttp2_header> move_headers() {
550
- return std::move(current_headers_);
551
- }
552
-
553
- inline nghttp2_headers_category headers_category() const {
554
- return current_headers_category_;
555
- }
556
-
557
- void StartHeaders(nghttp2_headers_category category);
558
-
559
- // Required for StreamBase
560
- bool IsAlive() override {
561
- return true;
562
- }
563
-
564
- // Required for StreamBase
565
- bool IsClosing() override {
566
- return false;
567
- }
568
-
569
- AsyncWrap* GetAsyncWrap() override { return this; }
570
-
571
- int DoWrite(WriteWrap* w, uv_buf_t* bufs, size_t count,
572
- uv_stream_t* send_handle) override;
573
-
574
- void MemoryInfo(MemoryTracker* tracker) const override {
575
- tracker->TrackField("current_headers", current_headers_);
576
- tracker->TrackField("queue", queue_);
577
- }
578
-
579
- SET_MEMORY_INFO_NAME(Http2Stream)
580
- SET_SELF_SIZE(Http2Stream)
581
-
582
- std::string diagnostic_name() const override;
583
-
584
- // JavaScript API
585
- static void GetID(const FunctionCallbackInfo<Value>& args);
586
- static void Destroy(const FunctionCallbackInfo<Value>& args);
587
- static void FlushData(const FunctionCallbackInfo<Value>& args);
588
- static void Priority(const FunctionCallbackInfo<Value>& args);
589
- static void PushPromise(const FunctionCallbackInfo<Value>& args);
590
- static void RefreshState(const FunctionCallbackInfo<Value>& args);
591
- static void Info(const FunctionCallbackInfo<Value>& args);
592
- static void Trailers(const FunctionCallbackInfo<Value>& args);
593
- static void Respond(const FunctionCallbackInfo<Value>& args);
594
- static void RstStream(const FunctionCallbackInfo<Value>& args);
595
-
596
- class Provider;
597
-
598
- struct Statistics {
599
- uint64_t start_time;
600
- uint64_t end_time;
601
- uint64_t first_header; // Time first header was received
602
- uint64_t first_byte; // Time first DATA frame byte was received
603
- uint64_t first_byte_sent; // Time first DATA frame byte was sent
604
- uint64_t sent_bytes;
605
- uint64_t received_bytes;
606
- };
607
-
608
- Statistics statistics_ = {};
609
-
610
- private:
611
- Http2Stream(Http2Session* session,
612
- v8::Local<v8::Object> obj,
613
- int32_t id,
614
- nghttp2_headers_category category,
615
- int options);
616
-
617
- Http2Session* session_ = nullptr; // The Parent HTTP/2 Session
618
- int32_t id_ = 0; // The Stream Identifier
619
- int32_t code_ = NGHTTP2_NO_ERROR; // The RST_STREAM code (if any)
620
- int flags_ = NGHTTP2_STREAM_FLAG_NONE; // Internal state flags
621
-
622
- uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
623
- uint32_t max_header_length_ = DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
624
-
625
- // The Current Headers block... As headers are received for this stream,
626
- // they are temporarily stored here until the OnFrameReceived is called
627
- // signalling the end of the HEADERS frame
628
- nghttp2_headers_category current_headers_category_ = NGHTTP2_HCAT_HEADERS;
629
- uint32_t current_headers_length_ = 0; // total number of octets
630
- std::vector<nghttp2_header> current_headers_;
631
-
632
- // This keeps track of the amount of data read from the socket while the
633
- // socket was in paused mode. When `ReadStart()` is called (and not before
634
- // then), we tell nghttp2 that we consumed that data to get proper
635
- // backpressure handling.
636
- size_t inbound_consumed_data_while_paused_ = 0;
637
-
638
- // Outbound Data... This is the data written by the JS layer that is
639
- // waiting to be written out to the socket.
640
- std::queue<nghttp2_stream_write> queue_;
641
- size_t available_outbound_length_ = 0;
642
-
643
- Http2StreamListener stream_listener_;
644
-
645
- friend class Http2Session;
646
- };
647
-
648
- class Http2Stream::Provider {
649
- public:
650
- Provider(Http2Stream* stream, int options);
651
- explicit Provider(int options);
652
- virtual ~Provider();
653
-
654
- nghttp2_data_provider* operator*() {
655
- return !empty_ ? &provider_ : nullptr;
656
- }
657
-
658
- class FD;
659
- class Stream;
660
- protected:
661
- nghttp2_data_provider provider_;
662
-
663
- private:
664
- bool empty_ = false;
665
- };
666
-
667
- class Http2Stream::Provider::Stream : public Http2Stream::Provider {
668
- public:
669
- Stream(Http2Stream* stream, int options);
670
- explicit Stream(int options);
671
-
672
- static ssize_t OnRead(nghttp2_session* session,
673
- int32_t id,
674
- uint8_t* buf,
675
- size_t length,
676
- uint32_t* flags,
677
- nghttp2_data_source* source,
678
- void* user_data);
679
- };
680
-
681
- // Indices for js_fields_, which serves as a way to communicate data with JS
682
- // land fast. In particular, we store information about the number/presence
683
- // of certain event listeners in JS, and skip calls from C++ into JS if they
684
- // are missing.
685
- enum SessionUint8Fields {
686
- kBitfield, // See below
687
- kSessionPriorityListenerCount,
688
- kSessionFrameErrorListenerCount,
689
- kSessionUint8FieldCount
690
- };
691
-
692
- enum SessionBitfieldFlags {
693
- kSessionHasRemoteSettingsListeners,
694
- kSessionRemoteSettingsIsUpToDate,
695
- kSessionHasPingListeners,
696
- kSessionHasAltsvcListeners
697
- };
698
-
699
- class Http2Session : public AsyncWrap, public StreamListener {
700
- public:
701
- Http2Session(Environment* env,
702
- Local<Object> wrap,
703
- nghttp2_session_type type = NGHTTP2_SESSION_SERVER);
704
- ~Http2Session() override;
705
-
706
- class Http2Ping;
707
- class Http2Settings;
708
- class MemoryAllocatorInfo;
709
-
710
- void EmitStatistics();
711
-
712
- inline StreamBase* underlying_stream() {
713
- return static_cast<StreamBase*>(stream_);
714
- }
715
-
716
- void Start();
717
- void Stop();
718
- void Close(uint32_t code = NGHTTP2_NO_ERROR,
719
- bool socket_closed = false);
720
- void Consume(Local<External> external);
721
- void Unconsume();
722
- void Goaway(uint32_t code, int32_t lastStreamID, uint8_t* data, size_t len);
723
- void AltSvc(int32_t id,
724
- uint8_t* origin,
725
- size_t origin_len,
726
- uint8_t* value,
727
- size_t value_len);
728
- void Origin(nghttp2_origin_entry* ov, size_t count);
729
-
730
-
731
- bool Ping(v8::Local<v8::Function> function);
732
-
733
- uint8_t SendPendingData();
734
-
735
- // Submits a new request. If the request is a success, assigned
736
- // will be a pointer to the Http2Stream instance assigned.
737
- // This only works if the session is a client session.
738
- Http2Stream* SubmitRequest(
739
- nghttp2_priority_spec* prispec,
740
- nghttp2_nv* nva,
741
- size_t len,
742
- int32_t* ret,
743
- int options = 0);
744
-
745
- inline nghttp2_session_type type() const { return session_type_; }
746
-
747
- inline nghttp2_session* session() const { return session_; }
748
-
749
- inline nghttp2_session* operator*() { return session_; }
750
-
751
- inline uint32_t GetMaxHeaderPairs() const { return max_header_pairs_; }
752
-
753
- inline const char* TypeName() const;
754
-
755
- inline bool IsDestroyed() {
756
- return (flags_ & SESSION_STATE_CLOSED) || session_ == nullptr;
757
- }
758
-
759
- // Schedule a write if nghttp2 indicates it wants to write to the socket.
760
- void MaybeScheduleWrite();
761
-
762
- // Stop reading if nghttp2 doesn't want to anymore.
763
- void MaybeStopReading();
764
-
765
- // Returns pointer to the stream, or nullptr if stream does not exist
766
- inline Http2Stream* FindStream(int32_t id);
767
-
768
- inline bool CanAddStream();
769
-
770
- // Adds a stream instance to this session
771
- inline void AddStream(Http2Stream* stream);
772
-
773
- // Removes a stream instance from this session
774
- inline void RemoveStream(Http2Stream* stream);
775
-
776
- // Indicates whether there currently exist outgoing buffers for this stream.
777
- bool HasWritesOnSocketForStream(Http2Stream* stream);
778
-
779
- // Write data from stream_buf_ to the session
780
- ssize_t ConsumeHTTP2Data();
781
-
782
- void MemoryInfo(MemoryTracker* tracker) const override {
783
- tracker->TrackField("streams", streams_);
784
- tracker->TrackField("outstanding_pings", outstanding_pings_);
785
- tracker->TrackField("outstanding_settings", outstanding_settings_);
786
- tracker->TrackField("outgoing_buffers", outgoing_buffers_);
787
- tracker->TrackFieldWithSize("stream_buf", stream_buf_.len);
788
- tracker->TrackFieldWithSize("outgoing_storage", outgoing_storage_.size());
789
- tracker->TrackFieldWithSize("pending_rst_streams",
790
- pending_rst_streams_.size() * sizeof(int32_t));
791
- }
792
-
793
- SET_MEMORY_INFO_NAME(Http2Session)
794
- SET_SELF_SIZE(Http2Session)
795
-
796
- std::string diagnostic_name() const override;
797
-
798
- // Schedule an RstStream for after the current write finishes.
799
- inline void AddPendingRstStream(int32_t stream_id) {
800
- pending_rst_streams_.emplace_back(stream_id);
801
- }
802
-
803
- inline bool HasPendingRstStream(int32_t stream_id) {
804
- return pending_rst_streams_.end() != std::find(pending_rst_streams_.begin(),
805
- pending_rst_streams_.end(),
806
- stream_id);
807
- }
808
-
809
- // Handle reads/writes from the underlying network transport.
810
- void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
811
- void OnStreamAfterWrite(WriteWrap* w, int status) override;
812
-
813
- // The JavaScript API
814
- static void New(const FunctionCallbackInfo<Value>& args);
815
- static void Consume(const FunctionCallbackInfo<Value>& args);
816
- static void Unconsume(const FunctionCallbackInfo<Value>& args);
817
- static void Destroying(const FunctionCallbackInfo<Value>& args);
818
- static void Destroy(const FunctionCallbackInfo<Value>& args);
819
- static void Settings(const FunctionCallbackInfo<Value>& args);
820
- static void Request(const FunctionCallbackInfo<Value>& args);
821
- static void SetNextStreamID(const FunctionCallbackInfo<Value>& args);
822
- static void Goaway(const FunctionCallbackInfo<Value>& args);
823
- static void UpdateChunksSent(const FunctionCallbackInfo<Value>& args);
824
- static void RefreshState(const FunctionCallbackInfo<Value>& args);
825
- static void Ping(const FunctionCallbackInfo<Value>& args);
826
- static void AltSvc(const FunctionCallbackInfo<Value>& args);
827
- static void Origin(const FunctionCallbackInfo<Value>& args);
828
-
829
- template <get_setting fn>
830
- static void RefreshSettings(const FunctionCallbackInfo<Value>& args);
831
-
832
- template <get_setting fn>
833
- static void GetSettings(const FunctionCallbackInfo<Value>& args);
834
-
835
- uv_loop_t* event_loop() const {
836
- return env()->event_loop();
837
- }
838
-
839
- Http2Ping* PopPing();
840
- bool AddPing(Http2Ping* ping);
841
-
842
- Http2Settings* PopSettings();
843
- bool AddSettings(Http2Settings* settings);
844
-
845
- void IncrementCurrentSessionMemory(uint64_t amount) {
846
- current_session_memory_ += amount;
847
- }
848
-
849
- void DecrementCurrentSessionMemory(uint64_t amount) {
850
- #ifdef DEBUG
851
- CHECK_LE(amount, current_session_memory_);
852
- #endif
853
- current_session_memory_ -= amount;
854
- }
855
-
856
- // Tell our custom memory allocator that this rcbuf is independent of
857
- // this session now, and may outlive it.
858
- void StopTrackingRcbuf(nghttp2_rcbuf* buf);
859
-
860
- // Returns the current session memory including memory allocated by nghttp2,
861
- // the current outbound storage queue, and pending writes.
862
- uint64_t GetCurrentSessionMemory() {
863
- uint64_t total = current_session_memory_ + sizeof(Http2Session);
864
- total += current_nghttp2_memory_;
865
- total += outgoing_storage_.size();
866
- return total;
867
- }
868
-
869
- // Return true if current_session_memory + amount is less than the max
870
- bool IsAvailableSessionMemory(uint64_t amount) {
871
- return GetCurrentSessionMemory() + amount <= max_session_memory_;
872
- }
873
-
874
- struct Statistics {
875
- uint64_t start_time;
876
- uint64_t end_time;
877
- uint64_t ping_rtt;
878
- uint64_t data_sent;
879
- uint64_t data_received;
880
- uint32_t frame_count;
881
- uint32_t frame_sent;
882
- int32_t stream_count;
883
- size_t max_concurrent_streams;
884
- double stream_average_duration;
885
- };
886
-
887
- Statistics statistics_ = {};
888
-
889
- private:
890
- // Frame Padding Strategies
891
- ssize_t OnDWordAlignedPadding(size_t frameLength,
892
- size_t maxPayloadLen);
893
- ssize_t OnMaxFrameSizePadding(size_t frameLength,
894
- size_t maxPayloadLen);
895
- ssize_t OnCallbackPadding(size_t frameLength,
896
- size_t maxPayloadLen);
897
-
898
- // Frame Handler
899
- int HandleDataFrame(const nghttp2_frame* frame);
900
- void HandleGoawayFrame(const nghttp2_frame* frame);
901
- void HandleHeadersFrame(const nghttp2_frame* frame);
902
- void HandlePriorityFrame(const nghttp2_frame* frame);
903
- void HandleSettingsFrame(const nghttp2_frame* frame);
904
- void HandlePingFrame(const nghttp2_frame* frame);
905
- void HandleAltSvcFrame(const nghttp2_frame* frame);
906
- void HandleOriginFrame(const nghttp2_frame* frame);
907
-
908
- // nghttp2 callbacks
909
- static int OnBeginHeadersCallback(
910
- nghttp2_session* session,
911
- const nghttp2_frame* frame,
912
- void* user_data);
913
- static int OnHeaderCallback(
914
- nghttp2_session* session,
915
- const nghttp2_frame* frame,
916
- nghttp2_rcbuf* name,
917
- nghttp2_rcbuf* value,
918
- uint8_t flags,
919
- void* user_data);
920
- static int OnFrameReceive(
921
- nghttp2_session* session,
922
- const nghttp2_frame* frame,
923
- void* user_data);
924
- static int OnFrameNotSent(
925
- nghttp2_session* session,
926
- const nghttp2_frame* frame,
927
- int error_code,
928
- void* user_data);
929
- static int OnFrameSent(
930
- nghttp2_session* session,
931
- const nghttp2_frame* frame,
932
- void* user_data);
933
- static int OnStreamClose(
934
- nghttp2_session* session,
935
- int32_t id,
936
- uint32_t code,
937
- void* user_data);
938
- static int OnInvalidHeader(
939
- nghttp2_session* session,
940
- const nghttp2_frame* frame,
941
- nghttp2_rcbuf* name,
942
- nghttp2_rcbuf* value,
943
- uint8_t flags,
944
- void* user_data);
945
- static int OnDataChunkReceived(
946
- nghttp2_session* session,
947
- uint8_t flags,
948
- int32_t id,
949
- const uint8_t* data,
950
- size_t len,
951
- void* user_data);
952
- static ssize_t OnSelectPadding(
953
- nghttp2_session* session,
954
- const nghttp2_frame* frame,
955
- size_t maxPayloadLen,
956
- void* user_data);
957
- static int OnNghttpError(
958
- nghttp2_session* session,
959
- const char* message,
960
- size_t len,
961
- void* user_data);
962
- static int OnSendData(
963
- nghttp2_session* session,
964
- nghttp2_frame* frame,
965
- const uint8_t* framehd,
966
- size_t length,
967
- nghttp2_data_source* source,
968
- void* user_data);
969
- static int OnInvalidFrame(
970
- nghttp2_session* session,
971
- const nghttp2_frame* frame,
972
- int lib_error_code,
973
- void* user_data);
974
-
975
- struct Callbacks {
976
- inline explicit Callbacks(bool kHasGetPaddingCallback);
977
- inline ~Callbacks();
978
-
979
- nghttp2_session_callbacks* callbacks;
980
- };
981
-
982
- /* Use callback_struct_saved[kHasGetPaddingCallback ? 1 : 0] */
983
- static const Callbacks callback_struct_saved[2];
984
-
985
- // The underlying nghttp2_session handle
986
- nghttp2_session* session_;
987
-
988
- // JS-accessible numeric fields, as indexed by SessionUint8Fields.
989
- uint8_t js_fields_[kSessionUint8FieldCount] = {};
990
-
991
- // The session type: client or server
992
- nghttp2_session_type session_type_;
993
-
994
- // The maximum number of header pairs permitted for streams on this session
995
- uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
996
-
997
- // The maximum amount of memory allocated for this session
998
- uint64_t max_session_memory_ = DEFAULT_MAX_SESSION_MEMORY;
999
- uint64_t current_session_memory_ = 0;
1000
- // The amount of memory allocated by nghttp2 internals
1001
- uint64_t current_nghttp2_memory_ = 0;
1002
-
1003
- // The collection of active Http2Streams associated with this session
1004
- std::unordered_map<int32_t, Http2Stream*> streams_;
1005
-
1006
- int flags_ = SESSION_STATE_NONE;
1007
-
1008
- // The StreamBase instance being used for i/o
1009
- padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
1010
-
1011
- // use this to allow timeout tracking during long-lasting writes
1012
- uint32_t chunks_sent_since_last_write_ = 0;
1013
-
1014
- uv_buf_t stream_buf_ = uv_buf_init(nullptr, 0);
1015
- // When processing input data, either stream_buf_ab_ or stream_buf_allocation_
1016
- // will be set. stream_buf_ab_ is lazily created from stream_buf_allocation_.
1017
- v8::Global<v8::ArrayBuffer> stream_buf_ab_;
1018
- uv_buf_t stream_buf_allocation_ = uv_buf_init(nullptr, 0);
1019
- size_t stream_buf_offset_ = 0;
1020
-
1021
- size_t max_outstanding_pings_ = DEFAULT_MAX_PINGS;
1022
- std::queue<Http2Ping*> outstanding_pings_;
1023
-
1024
- size_t max_outstanding_settings_ = DEFAULT_MAX_SETTINGS;
1025
- std::queue<Http2Settings*> outstanding_settings_;
1026
-
1027
- std::vector<nghttp2_stream_write> outgoing_buffers_;
1028
- std::vector<uint8_t> outgoing_storage_;
1029
- size_t outgoing_length_ = 0;
1030
- std::vector<int32_t> pending_rst_streams_;
1031
- // Count streams that have been rejected while being opened. Exceeding a fixed
1032
- // limit will result in the session being destroyed, as an indication of a
1033
- // misbehaving peer. This counter is reset once new streams are being
1034
- // accepted again.
1035
- int32_t rejected_stream_count_ = 0;
1036
- // Also use the invalid frame count as a measure for rejecting input frames.
1037
- int32_t invalid_frame_count_ = 0;
1038
-
1039
- void PushOutgoingBuffer(nghttp2_stream_write&& write);
1040
- void CopyDataIntoOutgoing(const uint8_t* src, size_t src_length);
1041
- void ClearOutgoing(int status);
1042
-
1043
- friend class Http2Scope;
1044
- friend class Http2StreamListener;
1045
- };
1046
-
1047
- class Http2SessionPerformanceEntry : public PerformanceEntry {
1048
- public:
1049
- Http2SessionPerformanceEntry(
1050
- Environment* env,
1051
- const Http2Session::Statistics& stats,
1052
- nghttp2_session_type type) :
1053
- PerformanceEntry(env, "Http2Session", "http2",
1054
- stats.start_time,
1055
- stats.end_time),
1056
- ping_rtt_(stats.ping_rtt),
1057
- data_sent_(stats.data_sent),
1058
- data_received_(stats.data_received),
1059
- frame_count_(stats.frame_count),
1060
- frame_sent_(stats.frame_sent),
1061
- stream_count_(stats.stream_count),
1062
- max_concurrent_streams_(stats.max_concurrent_streams),
1063
- stream_average_duration_(stats.stream_average_duration),
1064
- session_type_(type) { }
1065
-
1066
- uint64_t ping_rtt() const { return ping_rtt_; }
1067
- uint64_t data_sent() const { return data_sent_; }
1068
- uint64_t data_received() const { return data_received_; }
1069
- uint32_t frame_count() const { return frame_count_; }
1070
- uint32_t frame_sent() const { return frame_sent_; }
1071
- int32_t stream_count() const { return stream_count_; }
1072
- size_t max_concurrent_streams() const { return max_concurrent_streams_; }
1073
- double stream_average_duration() const { return stream_average_duration_; }
1074
- nghttp2_session_type type() const { return session_type_; }
1075
-
1076
- void Notify(Local<Value> obj) {
1077
- PerformanceEntry::Notify(env(), kind(), obj);
1078
- }
1079
-
1080
- private:
1081
- uint64_t ping_rtt_;
1082
- uint64_t data_sent_;
1083
- uint64_t data_received_;
1084
- uint32_t frame_count_;
1085
- uint32_t frame_sent_;
1086
- int32_t stream_count_;
1087
- size_t max_concurrent_streams_;
1088
- double stream_average_duration_;
1089
- nghttp2_session_type session_type_;
1090
- };
1091
-
1092
- class Http2StreamPerformanceEntry : public PerformanceEntry {
1093
- public:
1094
- Http2StreamPerformanceEntry(
1095
- Environment* env,
1096
- int32_t id,
1097
- const Http2Stream::Statistics& stats) :
1098
- PerformanceEntry(env, "Http2Stream", "http2",
1099
- stats.start_time,
1100
- stats.end_time),
1101
- id_(id),
1102
- first_header_(stats.first_header),
1103
- first_byte_(stats.first_byte),
1104
- first_byte_sent_(stats.first_byte_sent),
1105
- sent_bytes_(stats.sent_bytes),
1106
- received_bytes_(stats.received_bytes) { }
1107
-
1108
- int32_t id() const { return id_; }
1109
- uint64_t first_header() const { return first_header_; }
1110
- uint64_t first_byte() const { return first_byte_; }
1111
- uint64_t first_byte_sent() const { return first_byte_sent_; }
1112
- uint64_t sent_bytes() const { return sent_bytes_; }
1113
- uint64_t received_bytes() const { return received_bytes_; }
1114
-
1115
- void Notify(Local<Value> obj) {
1116
- PerformanceEntry::Notify(env(), kind(), obj);
1117
- }
1118
-
1119
- private:
1120
- int32_t id_;
1121
- uint64_t first_header_;
1122
- uint64_t first_byte_;
1123
- uint64_t first_byte_sent_;
1124
- uint64_t sent_bytes_;
1125
- uint64_t received_bytes_;
1126
- };
1127
-
1128
- class Http2Session::Http2Ping : public AsyncWrap {
1129
- public:
1130
- explicit Http2Ping(Http2Session* session, v8::Local<v8::Object> obj);
1131
-
1132
- void MemoryInfo(MemoryTracker* tracker) const override {
1133
- tracker->TrackField("session", session_);
1134
- }
1135
-
1136
- SET_MEMORY_INFO_NAME(Http2Ping)
1137
- SET_SELF_SIZE(Http2Ping)
1138
-
1139
- void Send(uint8_t* payload);
1140
- void Done(bool ack, const uint8_t* payload = nullptr);
1141
-
1142
- private:
1143
- Http2Session* session_;
1144
- uint64_t startTime_;
1145
-
1146
- friend class Http2Session;
1147
- };
1148
-
1149
- // The Http2Settings class is used to parse the settings passed in for
1150
- // an Http2Session, converting those into an array of nghttp2_settings_entry
1151
- // structs.
1152
- class Http2Session::Http2Settings : public AsyncWrap {
1153
- public:
1154
- Http2Settings(Environment* env,
1155
- Http2Session* session,
1156
- v8::Local<v8::Object> obj,
1157
- uint64_t start_time = uv_hrtime());
1158
-
1159
- void MemoryInfo(MemoryTracker* tracker) const override {
1160
- tracker->TrackField("session", session_);
1161
- }
1162
-
1163
- SET_MEMORY_INFO_NAME(Http2Settings)
1164
- SET_SELF_SIZE(Http2Settings)
1165
-
1166
- void Send();
1167
- void Done(bool ack);
1168
-
1169
- // Returns a Buffer instance with the serialized SETTINGS payload
1170
- Local<Value> Pack();
1171
-
1172
- // Resets the default values in the settings buffer
1173
- static void RefreshDefaults(Environment* env);
1174
-
1175
- // Update the local or remote settings for the given session
1176
- static void Update(Environment* env,
1177
- Http2Session* session,
1178
- get_setting fn);
1179
-
1180
- private:
1181
- void Init();
1182
- Http2Session* session_;
1183
- uint64_t startTime_;
1184
- size_t count_ = 0;
1185
- nghttp2_settings_entry entries_[IDX_SETTINGS_COUNT];
1186
- };
1187
-
1188
- class ExternalHeader :
1189
- public String::ExternalOneByteStringResource {
1190
- public:
1191
- explicit ExternalHeader(nghttp2_rcbuf* buf)
1192
- : buf_(buf), vec_(nghttp2_rcbuf_get_buf(buf)) {
1193
- }
1194
-
1195
- ~ExternalHeader() override {
1196
- nghttp2_rcbuf_decref(buf_);
1197
- buf_ = nullptr;
1198
- }
1199
-
1200
- const char* data() const override {
1201
- return const_cast<const char*>(reinterpret_cast<char*>(vec_.base));
1202
- }
1203
-
1204
- size_t length() const override {
1205
- return vec_.len;
1206
- }
1207
-
1208
- static inline
1209
- MaybeLocal<String> GetInternalizedString(Environment* env,
1210
- const nghttp2_vec& vec) {
1211
- return String::NewFromOneByte(env->isolate(),
1212
- vec.base,
1213
- v8::NewStringType::kInternalized,
1214
- vec.len);
1215
- }
1216
-
1217
- template <bool may_internalize>
1218
- static MaybeLocal<String> New(Http2Session* session, nghttp2_rcbuf* buf) {
1219
- Environment* env = session->env();
1220
- if (nghttp2_rcbuf_is_static(buf)) {
1221
- auto& static_str_map = env->isolate_data()->http2_static_strs;
1222
- v8::Eternal<v8::String>& eternal = static_str_map[buf];
1223
- if (eternal.IsEmpty()) {
1224
- Local<String> str =
1225
- GetInternalizedString(env, nghttp2_rcbuf_get_buf(buf))
1226
- .ToLocalChecked();
1227
- eternal.Set(env->isolate(), str);
1228
- return str;
1229
- }
1230
- return eternal.Get(env->isolate());
1231
- }
1232
-
1233
- nghttp2_vec vec = nghttp2_rcbuf_get_buf(buf);
1234
- if (vec.len == 0) {
1235
- nghttp2_rcbuf_decref(buf);
1236
- return String::Empty(env->isolate());
1237
- }
1238
-
1239
- if (may_internalize && vec.len < 64) {
1240
- nghttp2_rcbuf_decref(buf);
1241
- // This is a short header name, so there is a good chance V8 already has
1242
- // it internalized.
1243
- return GetInternalizedString(env, vec);
1244
- }
1245
-
1246
- session->StopTrackingRcbuf(buf);
1247
- ExternalHeader* h_str = new ExternalHeader(buf);
1248
- MaybeLocal<String> str = String::NewExternalOneByte(env->isolate(), h_str);
1249
- if (str.IsEmpty())
1250
- delete h_str;
1251
-
1252
- return str;
1253
- }
1254
-
1255
- private:
1256
- nghttp2_rcbuf* buf_;
1257
- nghttp2_vec vec_;
1258
- };
1259
-
1260
- class Headers {
1261
- public:
1262
- Headers(Isolate* isolate, Local<Context> context, Local<Array> headers);
1263
- ~Headers() {}
1264
-
1265
- nghttp2_nv* operator*() {
1266
- return reinterpret_cast<nghttp2_nv*>(*buf_);
1267
- }
1268
-
1269
- size_t length() const {
1270
- return count_;
1271
- }
1272
-
1273
- private:
1274
- size_t count_;
1275
- MaybeStackBuffer<char, 3000> buf_;
1276
- };
1277
-
1278
- class Origins {
1279
- public:
1280
- Origins(Isolate* isolate,
1281
- Local<Context> context,
1282
- Local<v8::String> origin_string,
1283
- size_t origin_count);
1284
- ~Origins() {}
1285
-
1286
- nghttp2_origin_entry* operator*() {
1287
- return reinterpret_cast<nghttp2_origin_entry*>(*buf_);
1288
- }
1289
-
1290
- size_t length() const {
1291
- return count_;
1292
- }
1293
-
1294
- private:
1295
- size_t count_;
1296
- MaybeStackBuffer<char, 512> buf_;
1297
- };
1298
-
1299
- } // namespace http2
1300
- } // namespace node
1301
-
1302
- #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
1303
-
1304
- #endif // SRC_NODE_HTTP2_H_