uws-react-native 0.0.1-alpha.1

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 (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +84 -0
  3. package/UwsReactNative.podspec +71 -0
  4. package/android/build.gradle.kts +138 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/id/sufeni/oss/uwsreactnative/UwsReactNativePackage.kt +18 -0
  7. package/apple/OnLoad.mm +17 -0
  8. package/cpp/CMakeLists.txt +154 -0
  9. package/cpp/UwsReactNativeModule.cpp +191 -0
  10. package/cpp/UwsReactNativeModule.h +30 -0
  11. package/cpp/app/AppHost.h +37 -0
  12. package/cpp/app/AppRunner.h +88 -0
  13. package/cpp/app/CMakeLists.txt +39 -0
  14. package/cpp/app/HttpRequestObject.h +173 -0
  15. package/cpp/app/HttpResponseObject.h +623 -0
  16. package/cpp/app/RecognizedString.h +71 -0
  17. package/cpp/app/TemplatedAppObject.h +472 -0
  18. package/cpp/bridging/ArrayBuffer.h +150 -0
  19. package/cpp/bridging/CMakeLists.txt +34 -0
  20. package/cpp/jsi/Buffer.h +91 -0
  21. package/cpp/jsi/CMakeLists.txt +34 -0
  22. package/cpp/uSockets/bsd.c +767 -0
  23. package/cpp/uSockets/context.c +524 -0
  24. package/cpp/uSockets/crypto/openssl.c +858 -0
  25. package/cpp/uSockets/crypto/sni_tree.cpp +218 -0
  26. package/cpp/uSockets/eventing/asio.cpp +475 -0
  27. package/cpp/uSockets/eventing/epoll_kqueue.c +458 -0
  28. package/cpp/uSockets/eventing/gcd.c +278 -0
  29. package/cpp/uSockets/eventing/libuv.c +305 -0
  30. package/cpp/uSockets/internal/eventing/asio.h +45 -0
  31. package/cpp/uSockets/internal/eventing/epoll_kqueue.h +67 -0
  32. package/cpp/uSockets/internal/eventing/gcd.h +40 -0
  33. package/cpp/uSockets/internal/eventing/libuv.h +45 -0
  34. package/cpp/uSockets/internal/internal.h +224 -0
  35. package/cpp/uSockets/internal/loop_data.h +38 -0
  36. package/cpp/uSockets/internal/networking/bsd.h +109 -0
  37. package/cpp/uSockets/io_uring/internal.h +98 -0
  38. package/cpp/uSockets/io_uring/io_context.c +302 -0
  39. package/cpp/uSockets/io_uring/io_loop.c +422 -0
  40. package/cpp/uSockets/io_uring/io_socket.c +139 -0
  41. package/cpp/uSockets/libusockets.h +350 -0
  42. package/cpp/uSockets/loop.c +396 -0
  43. package/cpp/uSockets/quic.c +1071 -0
  44. package/cpp/uSockets/quic.h +68 -0
  45. package/cpp/uSockets/socket.c +231 -0
  46. package/cpp/uSockets/udp.c +151 -0
  47. package/cpp/uWebSockets/uWebSockets/App.h +676 -0
  48. package/cpp/uWebSockets/uWebSockets/AsyncSocket.h +376 -0
  49. package/cpp/uWebSockets/uWebSockets/AsyncSocketData.h +94 -0
  50. package/cpp/uWebSockets/uWebSockets/BloomFilter.h +83 -0
  51. package/cpp/uWebSockets/uWebSockets/CachingApp.h +115 -0
  52. package/cpp/uWebSockets/uWebSockets/ChunkedEncoding.h +237 -0
  53. package/cpp/uWebSockets/uWebSockets/ClientApp.h +36 -0
  54. package/cpp/uWebSockets/uWebSockets/Http3App.h +140 -0
  55. package/cpp/uWebSockets/uWebSockets/Http3Context.h +157 -0
  56. package/cpp/uWebSockets/uWebSockets/Http3ContextData.h +21 -0
  57. package/cpp/uWebSockets/uWebSockets/Http3Request.h +22 -0
  58. package/cpp/uWebSockets/uWebSockets/Http3Response.h +120 -0
  59. package/cpp/uWebSockets/uWebSockets/Http3ResponseData.h +25 -0
  60. package/cpp/uWebSockets/uWebSockets/HttpContext.h +521 -0
  61. package/cpp/uWebSockets/uWebSockets/HttpContextData.h +60 -0
  62. package/cpp/uWebSockets/uWebSockets/HttpErrors.h +53 -0
  63. package/cpp/uWebSockets/uWebSockets/HttpParser.h +747 -0
  64. package/cpp/uWebSockets/uWebSockets/HttpResponse.h +605 -0
  65. package/cpp/uWebSockets/uWebSockets/HttpResponseData.h +123 -0
  66. package/cpp/uWebSockets/uWebSockets/HttpRouter.h +384 -0
  67. package/cpp/uWebSockets/uWebSockets/LocalCluster.h +64 -0
  68. package/cpp/uWebSockets/uWebSockets/Loop.h +238 -0
  69. package/cpp/uWebSockets/uWebSockets/LoopData.h +113 -0
  70. package/cpp/uWebSockets/uWebSockets/MessageParser.h +64 -0
  71. package/cpp/uWebSockets/uWebSockets/MoveOnlyFunction.h +389 -0
  72. package/cpp/uWebSockets/uWebSockets/Multipart.h +231 -0
  73. package/cpp/uWebSockets/uWebSockets/PerMessageDeflate.h +303 -0
  74. package/cpp/uWebSockets/uWebSockets/ProxyParser.h +187 -0
  75. package/cpp/uWebSockets/uWebSockets/QueryParser.h +120 -0
  76. package/cpp/uWebSockets/uWebSockets/TopicTree.h +364 -0
  77. package/cpp/uWebSockets/uWebSockets/Utilities.h +66 -0
  78. package/cpp/uWebSockets/uWebSockets/WebSocket.h +407 -0
  79. package/cpp/uWebSockets/uWebSockets/WebSocketContext.h +436 -0
  80. package/cpp/uWebSockets/uWebSockets/WebSocketContextData.h +109 -0
  81. package/cpp/uWebSockets/uWebSockets/WebSocketData.h +86 -0
  82. package/cpp/uWebSockets/uWebSockets/WebSocketExtensions.h +256 -0
  83. package/cpp/uWebSockets/uWebSockets/WebSocketHandshake.h +145 -0
  84. package/cpp/uWebSockets/uWebSockets/WebSocketProtocol.h +525 -0
  85. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js +12 -0
  86. package/lib/commonjs/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  87. package/lib/commonjs/index.js +28 -0
  88. package/lib/commonjs/index.js.map +1 -0
  89. package/lib/commonjs/modules/App.js +17 -0
  90. package/lib/commonjs/modules/App.js.map +1 -0
  91. package/lib/commonjs/modules/CompressOptions.js +103 -0
  92. package/lib/commonjs/modules/CompressOptions.js.map +1 -0
  93. package/lib/commonjs/modules/EnvironmentVariables.js +17 -0
  94. package/lib/commonjs/modules/EnvironmentVariables.js.map +1 -0
  95. package/lib/commonjs/modules/ListenOptions.js +12 -0
  96. package/lib/commonjs/modules/ListenOptions.js.map +1 -0
  97. package/lib/commonjs/modules/SSLApp.js +15 -0
  98. package/lib/commonjs/modules/SSLApp.js.map +1 -0
  99. package/lib/commonjs/modules/getParts.js +28 -0
  100. package/lib/commonjs/modules/getParts.js.map +1 -0
  101. package/lib/commonjs/modules/index.js +61 -0
  102. package/lib/commonjs/modules/index.js.map +1 -0
  103. package/lib/commonjs/modules/us_listen_socket_close.js +21 -0
  104. package/lib/commonjs/modules/us_listen_socket_close.js.map +1 -0
  105. package/lib/commonjs/modules/us_socket_local_port.js +22 -0
  106. package/lib/commonjs/modules/us_socket_local_port.js.map +1 -0
  107. package/lib/commonjs/package.json +1 -0
  108. package/lib/commonjs/types/AppDescriptor.js +2 -0
  109. package/lib/commonjs/types/AppDescriptor.js.map +1 -0
  110. package/lib/commonjs/types/AppOptions.js +2 -0
  111. package/lib/commonjs/types/AppOptions.js.map +1 -0
  112. package/lib/commonjs/types/HttpRequest.js +6 -0
  113. package/lib/commonjs/types/HttpRequest.js.map +1 -0
  114. package/lib/commonjs/types/HttpResponse.js +6 -0
  115. package/lib/commonjs/types/HttpResponse.js.map +1 -0
  116. package/lib/commonjs/types/HttpRouterOptions.js +2 -0
  117. package/lib/commonjs/types/HttpRouterOptions.js.map +1 -0
  118. package/lib/commonjs/types/MultipartField.js +2 -0
  119. package/lib/commonjs/types/MultipartField.js.map +1 -0
  120. package/lib/commonjs/types/RecognizedString.js +2 -0
  121. package/lib/commonjs/types/RecognizedString.js.map +1 -0
  122. package/lib/commonjs/types/TemplatedApp.js +6 -0
  123. package/lib/commonjs/types/TemplatedApp.js.map +1 -0
  124. package/lib/commonjs/types/WebSocket.js +6 -0
  125. package/lib/commonjs/types/WebSocket.js.map +1 -0
  126. package/lib/commonjs/types/WebSocketBehaviour.js +139 -0
  127. package/lib/commonjs/types/WebSocketBehaviour.js.map +1 -0
  128. package/lib/commonjs/types/index.js +2 -0
  129. package/lib/commonjs/types/index.js.map +1 -0
  130. package/lib/commonjs/types/us_listen_socket.js +2 -0
  131. package/lib/commonjs/types/us_listen_socket.js.map +1 -0
  132. package/lib/commonjs/types/us_socket.js +2 -0
  133. package/lib/commonjs/types/us_socket.js.map +1 -0
  134. package/lib/commonjs/types/us_socket_context_t.js +2 -0
  135. package/lib/commonjs/types/us_socket_context_t.js.map +1 -0
  136. package/lib/module/_internal/native-modules/NativeReactNativeUws.js +10 -0
  137. package/lib/module/_internal/native-modules/NativeReactNativeUws.js.map +1 -0
  138. package/lib/module/index.js +5 -0
  139. package/lib/module/index.js.map +1 -0
  140. package/lib/module/modules/App.js +12 -0
  141. package/lib/module/modules/App.js.map +1 -0
  142. package/lib/module/modules/CompressOptions.js +103 -0
  143. package/lib/module/modules/CompressOptions.js.map +1 -0
  144. package/lib/module/modules/EnvironmentVariables.js +13 -0
  145. package/lib/module/modules/EnvironmentVariables.js.map +1 -0
  146. package/lib/module/modules/ListenOptions.js +8 -0
  147. package/lib/module/modules/ListenOptions.js.map +1 -0
  148. package/lib/module/modules/SSLApp.js +15 -0
  149. package/lib/module/modules/SSLApp.js.map +1 -0
  150. package/lib/module/modules/getParts.js +23 -0
  151. package/lib/module/modules/getParts.js.map +1 -0
  152. package/lib/module/modules/index.js +11 -0
  153. package/lib/module/modules/index.js.map +1 -0
  154. package/lib/module/modules/us_listen_socket_close.js +17 -0
  155. package/lib/module/modules/us_listen_socket_close.js.map +1 -0
  156. package/lib/module/modules/us_socket_local_port.js +18 -0
  157. package/lib/module/modules/us_socket_local_port.js.map +1 -0
  158. package/lib/module/package.json +1 -0
  159. package/lib/module/types/AppDescriptor.js +2 -0
  160. package/lib/module/types/AppDescriptor.js.map +1 -0
  161. package/lib/module/types/AppOptions.js +2 -0
  162. package/lib/module/types/AppOptions.js.map +1 -0
  163. package/lib/module/types/HttpRequest.js +4 -0
  164. package/lib/module/types/HttpRequest.js.map +1 -0
  165. package/lib/module/types/HttpResponse.js +4 -0
  166. package/lib/module/types/HttpResponse.js.map +1 -0
  167. package/lib/module/types/HttpRouterOptions.js +2 -0
  168. package/lib/module/types/HttpRouterOptions.js.map +1 -0
  169. package/lib/module/types/MultipartField.js +2 -0
  170. package/lib/module/types/MultipartField.js.map +1 -0
  171. package/lib/module/types/RecognizedString.js +2 -0
  172. package/lib/module/types/RecognizedString.js.map +1 -0
  173. package/lib/module/types/TemplatedApp.js +4 -0
  174. package/lib/module/types/TemplatedApp.js.map +1 -0
  175. package/lib/module/types/WebSocket.js +4 -0
  176. package/lib/module/types/WebSocket.js.map +1 -0
  177. package/lib/module/types/WebSocketBehaviour.js +139 -0
  178. package/lib/module/types/WebSocketBehaviour.js.map +1 -0
  179. package/lib/module/types/index.js +2 -0
  180. package/lib/module/types/index.js.map +1 -0
  181. package/lib/module/types/us_listen_socket.js +2 -0
  182. package/lib/module/types/us_listen_socket.js.map +1 -0
  183. package/lib/module/types/us_socket.js +2 -0
  184. package/lib/module/types/us_socket.js.map +1 -0
  185. package/lib/module/types/us_socket_context_t.js +2 -0
  186. package/lib/module/types/us_socket_context_t.js.map +1 -0
  187. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  188. package/lib/typescript/commonjs/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/index.d.ts +3 -0
  190. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/modules/App.d.ts +7 -0
  192. package/lib/typescript/commonjs/modules/App.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/modules/CompressOptions.d.ts +1 -0
  194. package/lib/typescript/commonjs/modules/CompressOptions.d.ts.map +1 -0
  195. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts +16 -0
  196. package/lib/typescript/commonjs/modules/EnvironmentVariables.d.ts.map +1 -0
  197. package/lib/typescript/commonjs/modules/ListenOptions.d.ts +5 -0
  198. package/lib/typescript/commonjs/modules/ListenOptions.d.ts.map +1 -0
  199. package/lib/typescript/commonjs/modules/SSLApp.d.ts +1 -0
  200. package/lib/typescript/commonjs/modules/SSLApp.d.ts.map +1 -0
  201. package/lib/typescript/commonjs/modules/getParts.d.ts +6 -0
  202. package/lib/typescript/commonjs/modules/getParts.d.ts.map +1 -0
  203. package/lib/typescript/commonjs/modules/index.d.ts +6 -0
  204. package/lib/typescript/commonjs/modules/index.d.ts.map +1 -0
  205. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts +5 -0
  206. package/lib/typescript/commonjs/modules/us_listen_socket_close.d.ts.map +1 -0
  207. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts +5 -0
  208. package/lib/typescript/commonjs/modules/us_socket_local_port.d.ts.map +1 -0
  209. package/lib/typescript/commonjs/package.json +1 -0
  210. package/lib/typescript/commonjs/types/AppDescriptor.d.ts +8 -0
  211. package/lib/typescript/commonjs/types/AppDescriptor.d.ts.map +1 -0
  212. package/lib/typescript/commonjs/types/AppOptions.d.ts +17 -0
  213. package/lib/typescript/commonjs/types/AppOptions.d.ts.map +1 -0
  214. package/lib/typescript/commonjs/types/HttpRequest.d.ts +54 -0
  215. package/lib/typescript/commonjs/types/HttpRequest.d.ts.map +1 -0
  216. package/lib/typescript/commonjs/types/HttpResponse.d.ts +169 -0
  217. package/lib/typescript/commonjs/types/HttpResponse.d.ts.map +1 -0
  218. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts +24 -0
  219. package/lib/typescript/commonjs/types/HttpRouterOptions.d.ts.map +1 -0
  220. package/lib/typescript/commonjs/types/MultipartField.d.ts +7 -0
  221. package/lib/typescript/commonjs/types/MultipartField.d.ts.map +1 -0
  222. package/lib/typescript/commonjs/types/RecognizedString.d.ts +10 -0
  223. package/lib/typescript/commonjs/types/RecognizedString.d.ts.map +1 -0
  224. package/lib/typescript/commonjs/types/TemplatedApp.d.ts +108 -0
  225. package/lib/typescript/commonjs/types/TemplatedApp.d.ts.map +1 -0
  226. package/lib/typescript/commonjs/types/WebSocket.d.ts +96 -0
  227. package/lib/typescript/commonjs/types/WebSocket.d.ts.map +1 -0
  228. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts +1 -0
  229. package/lib/typescript/commonjs/types/WebSocketBehaviour.d.ts.map +1 -0
  230. package/lib/typescript/commonjs/types/index.d.ts +6 -0
  231. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  232. package/lib/typescript/commonjs/types/us_listen_socket.d.ts +7 -0
  233. package/lib/typescript/commonjs/types/us_listen_socket.d.ts.map +1 -0
  234. package/lib/typescript/commonjs/types/us_socket.d.ts +7 -0
  235. package/lib/typescript/commonjs/types/us_socket.d.ts.map +1 -0
  236. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts +7 -0
  237. package/lib/typescript/commonjs/types/us_socket_context_t.d.ts.map +1 -0
  238. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts +22 -0
  239. package/lib/typescript/module/_internal/native-modules/NativeReactNativeUws.d.ts.map +1 -0
  240. package/lib/typescript/module/index.d.ts +3 -0
  241. package/lib/typescript/module/index.d.ts.map +1 -0
  242. package/lib/typescript/module/modules/App.d.ts +7 -0
  243. package/lib/typescript/module/modules/App.d.ts.map +1 -0
  244. package/lib/typescript/module/modules/CompressOptions.d.ts +1 -0
  245. package/lib/typescript/module/modules/CompressOptions.d.ts.map +1 -0
  246. package/lib/typescript/module/modules/EnvironmentVariables.d.ts +16 -0
  247. package/lib/typescript/module/modules/EnvironmentVariables.d.ts.map +1 -0
  248. package/lib/typescript/module/modules/ListenOptions.d.ts +5 -0
  249. package/lib/typescript/module/modules/ListenOptions.d.ts.map +1 -0
  250. package/lib/typescript/module/modules/SSLApp.d.ts +1 -0
  251. package/lib/typescript/module/modules/SSLApp.d.ts.map +1 -0
  252. package/lib/typescript/module/modules/getParts.d.ts +6 -0
  253. package/lib/typescript/module/modules/getParts.d.ts.map +1 -0
  254. package/lib/typescript/module/modules/index.d.ts +6 -0
  255. package/lib/typescript/module/modules/index.d.ts.map +1 -0
  256. package/lib/typescript/module/modules/us_listen_socket_close.d.ts +5 -0
  257. package/lib/typescript/module/modules/us_listen_socket_close.d.ts.map +1 -0
  258. package/lib/typescript/module/modules/us_socket_local_port.d.ts +5 -0
  259. package/lib/typescript/module/modules/us_socket_local_port.d.ts.map +1 -0
  260. package/lib/typescript/module/package.json +1 -0
  261. package/lib/typescript/module/types/AppDescriptor.d.ts +8 -0
  262. package/lib/typescript/module/types/AppDescriptor.d.ts.map +1 -0
  263. package/lib/typescript/module/types/AppOptions.d.ts +17 -0
  264. package/lib/typescript/module/types/AppOptions.d.ts.map +1 -0
  265. package/lib/typescript/module/types/HttpRequest.d.ts +54 -0
  266. package/lib/typescript/module/types/HttpRequest.d.ts.map +1 -0
  267. package/lib/typescript/module/types/HttpResponse.d.ts +169 -0
  268. package/lib/typescript/module/types/HttpResponse.d.ts.map +1 -0
  269. package/lib/typescript/module/types/HttpRouterOptions.d.ts +24 -0
  270. package/lib/typescript/module/types/HttpRouterOptions.d.ts.map +1 -0
  271. package/lib/typescript/module/types/MultipartField.d.ts +7 -0
  272. package/lib/typescript/module/types/MultipartField.d.ts.map +1 -0
  273. package/lib/typescript/module/types/RecognizedString.d.ts +10 -0
  274. package/lib/typescript/module/types/RecognizedString.d.ts.map +1 -0
  275. package/lib/typescript/module/types/TemplatedApp.d.ts +108 -0
  276. package/lib/typescript/module/types/TemplatedApp.d.ts.map +1 -0
  277. package/lib/typescript/module/types/WebSocket.d.ts +96 -0
  278. package/lib/typescript/module/types/WebSocket.d.ts.map +1 -0
  279. package/lib/typescript/module/types/WebSocketBehaviour.d.ts +1 -0
  280. package/lib/typescript/module/types/WebSocketBehaviour.d.ts.map +1 -0
  281. package/lib/typescript/module/types/index.d.ts +6 -0
  282. package/lib/typescript/module/types/index.d.ts.map +1 -0
  283. package/lib/typescript/module/types/us_listen_socket.d.ts +7 -0
  284. package/lib/typescript/module/types/us_listen_socket.d.ts.map +1 -0
  285. package/lib/typescript/module/types/us_socket.d.ts +7 -0
  286. package/lib/typescript/module/types/us_socket.d.ts.map +1 -0
  287. package/lib/typescript/module/types/us_socket_context_t.d.ts +7 -0
  288. package/lib/typescript/module/types/us_socket_context_t.d.ts.map +1 -0
  289. package/lib/typescript/tsconfig.tsbuildinfo +1 -0
  290. package/package.json +62 -0
  291. package/src/_internal/native-modules/NativeUwsReactNative.ts +40 -0
  292. package/src/index.ts +2 -0
  293. package/src/modules/App.ts +14 -0
  294. package/src/modules/CompressOptions.ts +101 -0
  295. package/src/modules/EnvironmentVariables.ts +16 -0
  296. package/src/modules/ListenOptions.ts +4 -0
  297. package/src/modules/SSLApp.ts +13 -0
  298. package/src/modules/getParts.ts +29 -0
  299. package/src/modules/index.ts +8 -0
  300. package/src/modules/us_listen_socket_close.ts +15 -0
  301. package/src/modules/us_socket_local_port.ts +16 -0
  302. package/src/types/AppDescriptor.ts +7 -0
  303. package/src/types/AppOptions.ts +22 -0
  304. package/src/types/HttpRequest.ts +74 -0
  305. package/src/types/HttpResponse.ts +309 -0
  306. package/src/types/HttpRouterOptions.ts +24 -0
  307. package/src/types/MultipartField.ts +6 -0
  308. package/src/types/RecognizedString.ts +11 -0
  309. package/src/types/TemplatedApp.ts +285 -0
  310. package/src/types/WebSocket.ts +147 -0
  311. package/src/types/WebSocketBehaviour.ts +137 -0
  312. package/src/types/index.ts +12 -0
  313. package/src/types/us_listen_socket.ts +6 -0
  314. package/src/types/us_socket.ts +6 -0
  315. package/src/types/us_socket_context_t.ts +6 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Options used when constructing an app. Especially for SSLApp.
3
+ * These are options passed directly to uSockets, C layer.
4
+ */
5
+ export interface AppOptions {
6
+ key_file_name?: string,
7
+
8
+ cert_file_name?: string,
9
+
10
+ ca_file_name?: string,
11
+
12
+ passphrase?: string,
13
+
14
+ dh_params_file_name?: string,
15
+
16
+ ssl_ciphers?: string,
17
+
18
+ /**
19
+ * This translates to SSL_MODE_RELEASE_BUFFERS
20
+ */
21
+ ssl_prefer_low_memory_usage?: boolean,
22
+ }
@@ -0,0 +1,74 @@
1
+ import type {
2
+ RecognizedString,
3
+ } from "./RecognizedString"
4
+
5
+ /**
6
+ * An HttpRequest is stack allocated and only accessible during the callback invocation.
7
+ */
8
+ export interface HttpRequest {
9
+ /**
10
+ * Loops over all headers.
11
+ */
12
+ forEach(
13
+ cb: (key: string, value: string) => void,
14
+ ) : void,
15
+
16
+ /**
17
+ * Returns the HTTP method as-is.
18
+ */
19
+ getCaseSensitiveMethod() : string,
20
+
21
+ /**
22
+ * Returns the lowercased header value or empty string.
23
+ */
24
+ getHeader(
25
+ lowerCaseKey: RecognizedString,
26
+ ) : string,
27
+
28
+ /**
29
+ * Returns the lowercased HTTP method, useful for "any" routes.
30
+ */
31
+ getMethod() : string,
32
+
33
+ /**
34
+ * Returns the parsed parameter at index. Corresponds to route. Can also take the name of the parameter.
35
+ *
36
+ * @example
37
+ * ```js
38
+ * app.get("/profile/:userID/:type", (res, req) => {
39
+ * // get userID
40
+ * console.log("userID", req.getParameter(0), req.getParameter("userID"))
41
+ *
42
+ * // get type
43
+ * console.log("type", req.getParameter(1), req.getParameter("type"))
44
+ * })
45
+ * ```
46
+ */
47
+ getParameter(
48
+ index: number | RecognizedString,
49
+ ) : string | undefined,
50
+
51
+ /**
52
+ * Returns the raw querystring (the part of URL after ? sign) or empty string.
53
+ */
54
+ getQuery() : string,
55
+
56
+ /**
57
+ * Returns a decoded query parameter value or undefined.
58
+ */
59
+ getQuery(
60
+ key: string,
61
+ ) : string | undefined,
62
+
63
+ /**
64
+ * Returns the URL including initial /slash
65
+ */
66
+ getUrl() : string,
67
+
68
+ /**
69
+ * Setting yield to true is to say that this route handler did not handle the route, causing the router to continue looking for a matching route handler, or fail.
70
+ */
71
+ setYield(
72
+ _yield: boolean,
73
+ ) : HttpRequest,
74
+ }
@@ -0,0 +1,309 @@
1
+ import type {
2
+ RecognizedString,
3
+ } from "./RecognizedString"
4
+
5
+ // import type {
6
+ // us_socket_context_t,
7
+ // } from "./us_socket_context_t"
8
+
9
+ /**
10
+ * An HttpResponse is valid until either onAborted callback or any of the .end/.tryEnd calls succeed. You may attach user data to this object.
11
+ */
12
+ export interface HttpResponse {
13
+ /**
14
+ * Immediately force closes the connection. Any onAborted callback will run.
15
+ */
16
+ close() : HttpResponse,
17
+
18
+ /**
19
+ * Corking a response is a performance improvement in both CPU and network, as you ready the IO system for writing multiple chunks at once.
20
+ *
21
+ * By default, you're corked in the immediately executing top portion of the route handler. In all other cases, such as when returning from
22
+ * await, or when being called back from an async database request or anything that isn't directly executing in the route handler, you'll want
23
+ * to cork before calling writeStatus, writeHeader or just write. Corking takes a callback in which you execute the writeHeader, writeStatus and
24
+ * such calls, in one atomic IO operation. This is important, not only for TCP but definitely for TLS where each write would otherwise result
25
+ * in one TLS block being sent off, each with one send syscall.
26
+ *
27
+ * Example usage:
28
+ *
29
+ * ```
30
+ * res.cork(() => {
31
+ * res.writeStatus("200 OK").writeHeader("Some", "Value").write("Hello world!"),
32
+ * }),
33
+ * ```
34
+ */
35
+ cork(
36
+ cb: () => void,
37
+ ) : HttpResponse,
38
+
39
+ // TODO
40
+ // It is a custom method from uWebSockets.js.
41
+ // I don't know how to implement this in React Native, since the JS call is always late than
42
+ // our predefined `res->onDataV2` which already running and even may finished earlier.
43
+ // /**
44
+ // * `collectBody` is a helper function making optimal use of the new onDataV2.
45
+ // * It allows efficient and easy collection of smallish HTTP request body data into RAM.
46
+ // * It accumulates all data chunks and calls handler with the complete body as an ArrayBuffer once all data has arrived.
47
+ // * If the total body size exceeds maxSize bytes, handler is called with null instead.
48
+ // */
49
+ // collectBody(
50
+ // maxSize: number,
51
+ // handler: (fullBody: ArrayBuffer | null) => void,
52
+ // ) : HttpResponse,
53
+
54
+ /**
55
+ * Ends this response by copying the contents of body.
56
+ */
57
+ end(
58
+ body?: RecognizedString,
59
+ closeConnection?: boolean,
60
+ ) : HttpResponse,
61
+
62
+ /**
63
+ * Ends this response without a body.
64
+ */
65
+ endWithoutBody(
66
+ reportedContentLength?: number,
67
+ closeConnection?: boolean,
68
+ ) : HttpResponse,
69
+
70
+ // Would be implemented until ArrayBuffer supported by React Native
71
+ // /**
72
+ // * Returns the remote IP address in binary format (4 or 16 bytes).
73
+ // */
74
+ // getRemoteAddress() : ArrayBuffer,
75
+
76
+ /**
77
+ * Returns the remote IP address as text.
78
+ */
79
+ getRemoteAddressAsText() : string,
80
+
81
+ /**
82
+ * Returns the remote port number.
83
+ */
84
+ getRemotePort() : number,
85
+
86
+ // TODO
87
+ // Would be implemented until SSL has been implemented
88
+ // /**
89
+ // * Returns the remote IP address in binary format (4 or 16 bytes), as reported by the PROXY Protocol v2 compatible proxy.
90
+ // */
91
+ // getProxiedRemoteAddress() : ArrayBuffer,
92
+
93
+ // TODO
94
+ // Would be implemented until the SSL has been implemented
95
+ // /**
96
+ // * Returns the remote IP address as text, as reported by the PROXY Protocol v2 compatible proxy.
97
+ // */
98
+ // getProxiedRemoteAddressAsText() : string,
99
+
100
+ // Would be implemented until we support the Proxy
101
+ // /**
102
+ // * Returns the remote port number, as reported by the PROXY Protocol v2 compatible proxy.
103
+ // */
104
+ // getProxiedRemotePort() : number,
105
+
106
+ /**
107
+ * Returns the global byte write offset for this response. Use with onWritable.
108
+ */
109
+ getWriteOffset() : number,
110
+
111
+ /**
112
+ * Every HttpResponse MUST have an attached abort handler.
113
+ * If you do not respond to it immediately inside of the callback.
114
+ * Returning from an Http request handler without attaching
115
+ * (by calling onAborted) an abort handler is ill-use and will terminate.
116
+ * When this event emits, the response has been aborted and may not be used.
117
+ */
118
+ onAborted(
119
+ handler: () => void,
120
+ ) : HttpResponse,
121
+
122
+ /**
123
+ * Handler for reading HTTP request body data.
124
+ * Must be attached before performing any asynchronous operation, otherwise data may be lost.
125
+ * You MUST copy the data of chunk if isLast is not true. We Neuter ArrayBuffers on return, making them zero length.
126
+ *
127
+ * ---
128
+ *
129
+ * **Note**
130
+ *
131
+ * If you have ever used uWebSockets or uWebSockets.js for Node.js,
132
+ * this handler/callback might be called lesser amount of times than normal uWebSockets due to predefined `onDataV2`
133
+ * that we already passed earlier in C++ side, and it might already finished before JS does an assignment or attachment to `onData`.
134
+ *
135
+ * We have to pass the `onDataV2` lambda in C++ early because doing late assignment to the `onDataV2` handler will do nothing or our handler is never getting called. This is also due to uWebSockets run at different thread, and make any JS calls always late (asynchronously), and that is also by design to prevent Main/UI thread blocking.
136
+ */
137
+ onData(
138
+ handler: (
139
+ chunk: ArrayBuffer,
140
+ isLast: boolean,
141
+ ) => void,
142
+ ) : void,
143
+
144
+ /**
145
+ * Handler for reading HTTP request body data. V2.
146
+ *
147
+ * Must be attached before performing any asynchronous operation, otherwise data may be lost.
148
+ * You MUST copy the data of chunk if maxRemainingBodyLength is not 0n. We Neuter ArrayBuffers on return, making them zero length.
149
+ *
150
+ * maxRemainingBodyLength is the known maximum of the remaining body length. Can be used to preallocate a receive buffer.
151
+ *
152
+ * ---
153
+ *
154
+ * **Note**
155
+ *
156
+ * If you have ever used uWebSockets or uWebSockets.js for Node.js,
157
+ * this handler/callback might be called lesser amount of times than normal uWebSockets due to predefined `onDataV2`
158
+ * that we already passed earlier in C++ side, and it might already finished before JS does an assignment or attachment to `onDataV2`.
159
+ *
160
+ * We have to pass the `onDataV2` lambda in C++ early because doing late assignment to the `onDataV2` handler will do nothing or our handler is never getting called. This is also due to uWebSockets run at different thread, and make any JS calls always late (asynchronously), and that is also by design to prevent Main/UI thread blocking.
161
+ */
162
+ onDataV2(
163
+ handler: (
164
+ chunk: ArrayBuffer,
165
+ maxRemainingBodyLength: bigint,
166
+ ) => void,
167
+ ) : void,
168
+
169
+ /**
170
+ * Handler for reading HTTP request body data only when all the body data has been retrieved,
171
+ * or the body size has reached the `maxBodySize` limit from your route handler options.
172
+ * A good case for a simple route handler that only needs to read complete body data.
173
+ *
174
+ * Not like the `onData` and `onDataV2`, this is a good option to save a bit of operation cost
175
+ * because uws-react-native passes an ArrayBuffer from C++ to JS only once when it is finished.
176
+ *
177
+ * This is an equivalent of `res.collectBody()` method from uWebSockets.js for Node.js,
178
+ * but to set max byte of body size, you have to set it through router options at the third arguments.
179
+ *
180
+ * @example
181
+ * ```
182
+ * app.post("/create", (res, req) => {
183
+ * let isAborted = false
184
+ * res.onAborted(() => {
185
+ * isAborted = true
186
+ * })
187
+ *
188
+ * if(!isAborted) {
189
+ * res.onFullData(chunk => {
190
+ * if(!isAborted) {
191
+ * res.end(`Body size is ${chunk.byteLength}`)
192
+ * }
193
+ * })
194
+ * }
195
+ * }, {
196
+ * maxBodySize: 1024 * 1024, // 1MB in byte
197
+ * })
198
+ * ```
199
+ */
200
+ onFullData(
201
+ handler: (
202
+ chunk: ArrayBuffer,
203
+ ) => void,
204
+ ) : void,
205
+
206
+ /**
207
+ * Similar to `onFullData`, but it is for reading HTTP request body data in raw text.
208
+ *
209
+ * This is an alternative method to read ArrayBuffer chunk in string because the TextDecoder is
210
+ * missing in React Native 0.84 and older.
211
+ */
212
+ onFullDataText(
213
+ handler: (
214
+ chunk: string,
215
+ ) => void,
216
+ ) : void,
217
+
218
+ // TODO
219
+ // Implement it later.
220
+ // /**
221
+ // * Registers a handler for writable events. Continue failed write attempts in here.
222
+ // * You MUST return true for success, false for failure.
223
+ // * Writing nothing is always success, so by default you must return true.
224
+ // */
225
+ // onWritable(
226
+ // handler: (offset: number) => boolean,
227
+ // ) : HttpResponse,
228
+
229
+ /**
230
+ * Pause HTTP request body streaming (throttle).
231
+ * Some buffered data may still be sent to onData.
232
+ */
233
+ pause() : void,
234
+
235
+ /**
236
+ * Resume HTTP request body streaming (unthrottle).
237
+ */
238
+ resume() : void,
239
+
240
+ /**
241
+ * Ends this response, or tries to, by streaming appropriately sized chunks of body. Use in conjunction with onWritable. Returns tuple [ok, hasResponded].
242
+ */
243
+ tryEnd(
244
+ fullBodyOrChunk: RecognizedString,
245
+ totalSize: number,
246
+ ) : [boolean, boolean],
247
+
248
+ // TODO
249
+ // Implement this method later.
250
+ // /**
251
+ // * Upgrades a HttpResponse to a WebSocket. See UpgradeAsync, UpgradeSync example files.
252
+ // *
253
+ // * Currently, this library is only supported string for the user data.
254
+ // * As an object alternative, you can use `JSON.stringify` to this method,
255
+ // * and retrieve the user data back from ws.getUserData() with `JSON.parse`.
256
+ // */
257
+ // upgrade/* <UserData extends object> */(
258
+ // // userData: UserData,
259
+ // userData: string,
260
+ // secWebSocketKey: RecognizedString,
261
+ // secWebSocketProtocol: RecognizedString,
262
+ // secWebSocketExtensions: RecognizedString,
263
+ // context: us_socket_context_t,
264
+ // ) : void,
265
+
266
+ /**
267
+ * Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. Returns true if no backpressure was added.
268
+ */
269
+ write(
270
+ chunk: RecognizedString,
271
+ ) : boolean,
272
+
273
+ /**
274
+ * Writes key and value to HTTP response.
275
+ * See writeStatus and corking.
276
+ */
277
+ writeHeader(
278
+ key: RecognizedString,
279
+ value: RecognizedString,
280
+ ) : HttpResponse,
281
+
282
+ /**
283
+ * Writes the HTTP status message such as "200 OK".
284
+ * This has to be called first in any response, otherwise
285
+ * it will be called automatically with "200 OK".
286
+ *
287
+ * If you want to send custom headers in a WebSocket
288
+ * upgrade response, you have to call writeStatus with
289
+ * "101 Switching Protocols" before you call writeHeader,
290
+ * otherwise your first call to writeHeader will call
291
+ * writeStatus with "200 OK" and the upgrade will fail.
292
+ *
293
+ * As you can imagine, we format outgoing responses in a linear
294
+ * buffer, not in a hash table. You can read about this in
295
+ * the user manual under "corking".
296
+ */
297
+ writeStatus(
298
+ status: RecognizedString,
299
+ ) : HttpResponse,
300
+
301
+ // TODO
302
+ // the `upgrade` method needs to be implemented first,
303
+ // but I also don't know how to attach arbitrary UserData to the HttpRequest object JSI C++.
304
+ // Probably, I would tell user to get the data explicitly from the ws.getUserData() method
305
+ // /**
306
+ // * Arbitrary user data may be attached to this object
307
+ // */
308
+ // [key: string]: unknown,
309
+ }
@@ -0,0 +1,24 @@
1
+ export interface HttpRouterOptions {
2
+ /**
3
+ * Optimize specific route handler by disable body reading.
4
+ * The `onData`, `onDataV2`, and `onFullData` method from response object will do nothing
5
+ * if the body read is disabled.
6
+ *
7
+ * This is an actual optimization, because uws-react-native has to predefined the body read
8
+ * (the res->onDataV2) internally from C++ side by default. So if you disable body reading
9
+ * in a specific route handler, uws-react-native will not do the predefined res->onDataV2 from C++ side at all.
10
+ *
11
+ * The reason why uws-react-native has to predefined the res->onDataV2 from C++ side, it is because we cannot do a sync call from uWebSockets C++ which run in arbitrary thread to JS, and late onDataV2 assignment will losing the body data. It is also by design that we run uWebSockets in another thread to prevent Main/UI thread blocking.
12
+ */
13
+ disableBodyRead?: boolean,
14
+
15
+ /**
16
+ * Limit max body data size reading in byte after it is accumulated with the next chunk. 1 mega bytes maxBodySize doesn't mean you will get 1 mega bytes data.
17
+ *
18
+ * This is useful to help the method from `HttpResponse` object
19
+ * like `onData`, `onDataV2`, and `onFullData` to limit the chunk you need to read from a request.
20
+ *
21
+ * This option does nothing if `disableBodyRead` option is true.
22
+ */
23
+ maxBodySize?: number,
24
+ }
@@ -0,0 +1,6 @@
1
+ export interface MultipartField {
2
+ data: ArrayBuffer,
3
+ name: string,
4
+ type?: string,
5
+ filename?: string,
6
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Recognized string types, things C++ can read and understand as strings.
3
+ * "String" does not have to mean "text", it can also be "binary".
4
+ *
5
+ * Ironically, JavaScript strings are the least performant of all options, to pass or receive to/from C++.
6
+ * This because we expect UTF-8. JavaScript strings are Latin-1 or UTF-16 internally meaning extra copies and reinterpretation are required.
7
+ * That's why all events pass data by ArrayBuffer and not JavaScript strings, as they allow zero-copy data passing.
8
+ */
9
+ export type RecognizedString =
10
+ | string
11
+ | ArrayBuffer