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,237 @@
1
+ /*
2
+ * Authored by Alex Hultman, 2018-2026.
3
+ * Intellectual property of third-party.
4
+
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #ifndef UWS_CHUNKEDENCODING_H
19
+ #define UWS_CHUNKEDENCODING_H
20
+
21
+ /* Independent chunked encoding parser, used by HttpParser. */
22
+
23
+ #include <string>
24
+ #include <cstring>
25
+ #include <cstdlib>
26
+ #include <algorithm>
27
+ #include <string_view>
28
+ #include "MoveOnlyFunction.h"
29
+ #include <optional>
30
+
31
+ namespace uWS {
32
+
33
+ constexpr uint64_t STATE_HAS_SIZE = 1ull << (sizeof(uint64_t) * 8 - 1);//0x80000000;
34
+ constexpr uint64_t STATE_IS_CHUNKED = 1ull << (sizeof(uint64_t) * 8 - 2);//0x40000000;
35
+ constexpr uint64_t STATE_SIZE_MASK = ~(3ull << (sizeof(uint64_t) * 8 - 2));//0x3FFFFFFF;
36
+ constexpr uint64_t STATE_IS_ERROR = ~0ull;//0xFFFFFFFF;
37
+ constexpr uint64_t STATE_SIZE_OVERFLOW = 0x0Full << (sizeof(uint64_t) * 8 - 8);//0x0F000000;
38
+
39
+ inline uint64_t chunkSize(uint64_t state) {
40
+ return state & STATE_SIZE_MASK;
41
+ }
42
+
43
+ /* Reads hex number until CR or out of data to consume. Updates state. Returns bytes consumed. */
44
+ inline void consumeHexNumber(std::string_view &data, uint64_t &state) {
45
+ /* Consume everything higher than 32 */
46
+ while (data.length() && data.data()[0] > 32) {
47
+
48
+ unsigned char digit = (unsigned char)data.data()[0];
49
+ if (digit >= 'a') {
50
+ digit = (unsigned char) (digit - ('a' - ':'));
51
+ } else if (digit >= 'A') {
52
+ digit = (unsigned char) (digit - ('A' - ':'));
53
+ }
54
+
55
+ unsigned int number = ((unsigned int) digit - (unsigned int) '0');
56
+
57
+ if (number > 16 || (chunkSize(state) & STATE_SIZE_OVERFLOW)) {
58
+ state = STATE_IS_ERROR;
59
+ return;
60
+ }
61
+
62
+ // extract state bits
63
+ uint64_t bits = /*state &*/ STATE_IS_CHUNKED;
64
+
65
+ state = (state & STATE_SIZE_MASK) * 16ull + number;
66
+
67
+ state |= bits;
68
+ data.remove_prefix(1);
69
+ }
70
+ /* Consume everything not /n */
71
+ while (data.length() && data.data()[0] != '\n') {
72
+ data.remove_prefix(1);
73
+ }
74
+ /* Now we stand on \n so consume it and enable size */
75
+ if (data.length()) {
76
+ state += 2; // include the two last /r/n
77
+ state |= STATE_HAS_SIZE | STATE_IS_CHUNKED;
78
+ data.remove_prefix(1);
79
+ }
80
+ }
81
+
82
+ inline void decChunkSize(uint64_t &state, unsigned int by) {
83
+
84
+ //unsigned int bits = state & STATE_IS_CHUNKED;
85
+
86
+ state = (state & ~STATE_SIZE_MASK) | (chunkSize(state) - by);
87
+
88
+ //state |= bits;
89
+ }
90
+
91
+ inline bool hasChunkSize(uint64_t state) {
92
+ return state & STATE_HAS_SIZE;
93
+ }
94
+
95
+ /* Are we in the middle of parsing chunked encoding? */
96
+ inline bool isParsingChunkedEncoding(uint64_t state) {
97
+ return state & ~STATE_SIZE_MASK;
98
+ }
99
+
100
+ inline bool isParsingInvalidChunkedEncoding(uint64_t state) {
101
+ return state == STATE_IS_ERROR;
102
+ }
103
+
104
+ /* Returns next chunk (empty or not), or if all data was consumed, nullopt is returned. */
105
+ static std::optional<std::string_view> getNextChunk(std::string_view &data, uint64_t &state, bool trailer = false) {
106
+
107
+ while (data.length()) {
108
+
109
+ // if in "drop trailer mode", just drop up to what we have as size
110
+ if (((state & STATE_IS_CHUNKED) == 0) && hasChunkSize(state) && chunkSize(state)) {
111
+
112
+ //printf("Parsing trailer now\n");
113
+
114
+ while(data.length() && chunkSize(state)) {
115
+ data.remove_prefix(1);
116
+ decChunkSize(state, 1);
117
+
118
+ if (chunkSize(state) == 0) {
119
+
120
+ /* This is an actual place where we need 0 as state */
121
+ state = 0;
122
+
123
+ /* The parser MUST stop consuming here */
124
+ return std::nullopt;
125
+ }
126
+ }
127
+ continue;
128
+ }
129
+
130
+ if (!hasChunkSize(state)) {
131
+ consumeHexNumber(data, state);
132
+ if (isParsingInvalidChunkedEncoding(state)) {
133
+ return std::nullopt;
134
+ }
135
+ if (hasChunkSize(state) && chunkSize(state) == 2) {
136
+
137
+ //printf("Setting state to trailer-parsing and emitting empty chunk\n");
138
+
139
+ // set trailer state and increase size to 4
140
+ if (trailer) {
141
+ state = 4 /*| STATE_IS_CHUNKED*/ | STATE_HAS_SIZE;
142
+ } else {
143
+ state = 2 /*| STATE_IS_CHUNKED*/ | STATE_HAS_SIZE;
144
+ }
145
+
146
+ return std::string_view(nullptr, 0);
147
+ }
148
+ continue;
149
+ }
150
+
151
+ // do we have data to emit all?
152
+ if (data.length() >= chunkSize(state)) {
153
+ // emit all but 2 bytes then reset state to 0 and goto beginning
154
+ // not fin
155
+ std::string_view emitSoon;
156
+ bool shouldEmit = false;
157
+ if (chunkSize(state) > 2) {
158
+ emitSoon = std::string_view(data.data(), chunkSize(state) - 2);
159
+ shouldEmit = true;
160
+ }
161
+ data.remove_prefix(chunkSize(state));
162
+ state = STATE_IS_CHUNKED;
163
+ if (shouldEmit) {
164
+ return emitSoon;
165
+ }
166
+ continue;
167
+ } else {
168
+ /* We will consume all our input data */
169
+ std::string_view emitSoon;
170
+ if (chunkSize(state) > 2) {
171
+ uint64_t maximalAppEmit = chunkSize(state) - 2;
172
+ if (data.length() > maximalAppEmit) {
173
+ emitSoon = data.substr(0, maximalAppEmit);
174
+ } else {
175
+ //cb(data);
176
+ emitSoon = data;
177
+ }
178
+ }
179
+ decChunkSize(state, (unsigned int) data.length());
180
+ state |= STATE_IS_CHUNKED;
181
+ // new: decrease data by its size (bug)
182
+ data.remove_prefix(data.length()); // ny bug fix för getNextChunk
183
+ if (emitSoon.length()) {
184
+ return emitSoon;
185
+ } else {
186
+ return std::nullopt;
187
+ }
188
+ }
189
+ }
190
+
191
+ return std::nullopt;
192
+ }
193
+
194
+ /* This is really just a wrapper for convenience */
195
+ struct ChunkIterator {
196
+
197
+ std::string_view *data;
198
+ std::optional<std::string_view> chunk;
199
+ uint64_t *state;
200
+ bool trailer;
201
+
202
+ ChunkIterator(std::string_view *data, uint64_t *state, bool trailer = false) : data(data), state(state), trailer(trailer) {
203
+ chunk = uWS::getNextChunk(*data, *state, trailer);
204
+ }
205
+
206
+ ChunkIterator() {
207
+
208
+ }
209
+
210
+ ChunkIterator begin() {
211
+ return *this;
212
+ }
213
+
214
+ ChunkIterator end() {
215
+ return ChunkIterator();
216
+ }
217
+
218
+ std::string_view operator*() {
219
+ if (!chunk.has_value()) {
220
+ std::abort();
221
+ }
222
+ return chunk.value();
223
+ }
224
+
225
+ bool operator!=(const ChunkIterator &other) const {
226
+ return other.chunk.has_value() != chunk.has_value();
227
+ }
228
+
229
+ ChunkIterator &operator++() {
230
+ chunk = uWS::getNextChunk(*data, *state, trailer);
231
+ return *this;
232
+ }
233
+
234
+ };
235
+ }
236
+
237
+ #endif // UWS_CHUNKEDENCODING_H
@@ -0,0 +1,36 @@
1
+ #include "MoveOnlyFunction.h"
2
+ #include "WebSocketContext.h"
3
+ #include <string>
4
+
5
+ namespace uWS {
6
+
7
+ struct WebSocketClientBehavior {
8
+ MoveOnlyFunction<void()> open;
9
+ MoveOnlyFunction<void()> message;
10
+ MoveOnlyFunction<void()> close;
11
+ //MoveOnlyFunction<void()> failed;
12
+
13
+ };
14
+
15
+ struct ClientApp {
16
+
17
+ WebSocketContext<0, false, int> *webSocketContext;
18
+ // behöver ett nytt http context med minimal klient, som slår om till den riktiga websocketcontext
19
+ // om samma storlek på httpsocket och websocket blir det enkel övergång
20
+
21
+ ClientApp(WebSocketClientBehavior &&behavior) {
22
+ //webSocketContext = WebSocketContext<0, false, int>::create();
23
+ }
24
+
25
+ ClientApp &&connect(std::string url, std::string protocol = "") {
26
+
27
+ return std::move(*this);
28
+ }
29
+
30
+ void run() {
31
+
32
+ }
33
+
34
+ };
35
+
36
+ }
@@ -0,0 +1,140 @@
1
+ #include "App.h"
2
+
3
+ #include "Http3Response.h"
4
+ #include "Http3Request.h"
5
+ #include "Http3Context.h"
6
+
7
+ namespace uWS {
8
+
9
+ struct H3App {
10
+ Http3Context *http3Context;
11
+
12
+ H3App(SocketContextOptions options = {}) {
13
+ /* This conversion should not be needed */
14
+ us_quic_socket_context_options_t h3options = {};
15
+
16
+ h3options.key_file_name = strdup(options.key_file_name);
17
+ h3options.cert_file_name = strdup(options.cert_file_name);
18
+ h3options.passphrase = strdup(options.passphrase);
19
+
20
+ /* Create the http3 context */
21
+ http3Context = Http3Context::create((us_loop_t *)Loop::get(), h3options);
22
+
23
+ http3Context->init();
24
+ }
25
+
26
+ /* Disallow copying, only move */
27
+ H3App(const H3App &other) = delete;
28
+
29
+ H3App(H3App &&other) {
30
+ /* Move HttpContext */
31
+ http3Context = other.http3Context;
32
+ other.http3Context = nullptr;
33
+ }
34
+
35
+ /* Host, port, callback */
36
+ H3App &&listen(std::string host, int port, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler) {
37
+ if (!host.length()) {
38
+ return listen(port, std::move(handler));
39
+ }
40
+ handler(http3Context ? (us_listen_socket_t *) http3Context->listen(host.c_str(), port) : nullptr);
41
+ return std::move(*this);
42
+ }
43
+
44
+ /* Host, port, options, callback */
45
+ H3App &&listen(std::string host, int port, int options, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler) {
46
+ if (!host.length()) {
47
+ return listen(port, options, std::move(handler));
48
+ }
49
+ handler(http3Context ? (us_listen_socket_t *) http3Context->listen(host.c_str(), port) : nullptr);
50
+ return std::move(*this);
51
+ }
52
+
53
+ /* Port, callback */
54
+ H3App &&listen(int port, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler) {
55
+ handler(http3Context ? (us_listen_socket_t *) http3Context->listen(nullptr, port) : nullptr);
56
+ return std::move(*this);
57
+ }
58
+
59
+ /* Port, options, callback */
60
+ H3App &&listen(int port, int options, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler) {
61
+ handler(http3Context ? (us_listen_socket_t *) http3Context->listen(nullptr, port) : nullptr);
62
+ return std::move(*this);
63
+ }
64
+
65
+ H3App &&get(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
66
+ if (http3Context) {
67
+ http3Context->onHttp("GET", pattern, std::move(handler));
68
+ }
69
+ return std::move(*this);
70
+ }
71
+
72
+ H3App &&post(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
73
+ if (http3Context) {
74
+ http3Context->onHttp("POST", pattern, std::move(handler));
75
+ }
76
+ return std::move(*this);
77
+ }
78
+
79
+ H3App &&options(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
80
+ if (http3Context) {
81
+ http3Context->onHttp("OPTIONS", pattern, std::move(handler));
82
+ }
83
+ return std::move(*this);
84
+ }
85
+
86
+ H3App &&del(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
87
+ if (http3Context) {
88
+ http3Context->onHttp("DELETE", pattern, std::move(handler));
89
+ }
90
+ return std::move(*this);
91
+ }
92
+
93
+ H3App &&patch(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
94
+ if (http3Context) {
95
+ http3Context->onHttp("PATCH", pattern, std::move(handler));
96
+ }
97
+ return std::move(*this);
98
+ }
99
+
100
+ H3App &&put(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
101
+ if (http3Context) {
102
+ http3Context->onHttp("PUT", pattern, std::move(handler));
103
+ }
104
+ return std::move(*this);
105
+ }
106
+
107
+ H3App &&head(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
108
+ if (http3Context) {
109
+ http3Context->onHttp("HEAD", pattern, std::move(handler));
110
+ }
111
+ return std::move(*this);
112
+ }
113
+
114
+ H3App &&connect(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
115
+ if (http3Context) {
116
+ http3Context->onHttp("CONNECT", pattern, std::move(handler));
117
+ }
118
+ return std::move(*this);
119
+ }
120
+
121
+ H3App &&trace(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
122
+ if (http3Context) {
123
+ http3Context->onHttp("TRACE", pattern, std::move(handler));
124
+ }
125
+ return std::move(*this);
126
+ }
127
+
128
+ /* This one catches any method */
129
+ H3App &&any(std::string pattern, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&handler) {
130
+ if (http3Context) {
131
+ http3Context->onHttp("*", pattern, std::move(handler));
132
+ }
133
+ return std::move(*this);
134
+ }
135
+
136
+ void run() {
137
+ uWS::Loop::get()->run();
138
+ }
139
+ };
140
+ }
@@ -0,0 +1,157 @@
1
+
2
+ extern "C" {
3
+ #include "quic.h"
4
+ }
5
+
6
+ #include "Http3ContextData.h"
7
+ #include "Http3ResponseData.h"
8
+
9
+ namespace uWS {
10
+ struct Http3Context {
11
+ static Http3Context *create(us_loop_t *loop, us_quic_socket_context_options_t options) {
12
+
13
+ /* Create quic socket context (assumes h3 for now) */
14
+ auto *context = us_create_quic_socket_context(loop, options, sizeof(Http3ContextData));
15
+
16
+ /* Specify application callbacks */
17
+ us_quic_socket_context_on_stream_data(context, [](us_quic_stream_t *s, char *data, int length) {
18
+
19
+ Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s);
20
+
21
+ /* We never emit FIN here */
22
+ if (responseData->onData) {
23
+ responseData->onData({data, (size_t) length}, false);
24
+ }
25
+ });
26
+ us_quic_socket_context_on_stream_end(context, [](us_quic_stream_t *s) {
27
+
28
+ Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s);
29
+
30
+ /* Emit FIN to app */
31
+ if (responseData->onData) {
32
+ responseData->onData({nullptr, 0}, true);
33
+ }
34
+
35
+ /* Have we written our entire backpressure, if any? */
36
+ // if (responseData->buffer.length() && (responseData->bufferOffset == (int) responseData->buffer.length())) {
37
+ // printf("We got FIN and we have no backpressure, closing stream now!\n");
38
+ // //us_quic_stream_close(s);
39
+ // } else {
40
+ // //printf("We got FIN but we have data to write, so keeping connection half-closed!\n");
41
+ // }
42
+
43
+ });
44
+ us_quic_socket_context_on_stream_open(context, [](us_quic_stream_t *s, int is_client) {
45
+
46
+ printf("Stream open!\n");
47
+
48
+ /* Inplace init our per stream data */
49
+ new (us_quic_stream_ext(s)) Http3ResponseData();
50
+ });
51
+ us_quic_socket_context_on_close(context, [](us_quic_socket_t *s) {
52
+ printf("QUIC socket disconnected!\n");
53
+ });
54
+ us_quic_socket_context_on_stream_writable(context, [](us_quic_stream_t *s) {
55
+ Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s);
56
+
57
+ /* Either we handle the streaming or we let the application handle it */
58
+ if (responseData->onWritable) {
59
+ responseData->onWritable(responseData->offset);
60
+ } else {
61
+ int written = us_quic_stream_write(s, (char *) responseData->backpressure.data(), responseData->backpressure.length());
62
+ responseData->backpressure.erase(written);
63
+
64
+ if (responseData->backpressure.length() == 0) {
65
+ printf("wrote until end, shutting down now!\n");
66
+ us_quic_stream_shutdown(s);
67
+ us_quic_stream_close(s);
68
+ }
69
+ }
70
+ });
71
+ us_quic_socket_context_on_stream_headers(context, [](us_quic_stream_t *s) {
72
+
73
+ /* This is the main place of start for requests */
74
+ Http3ContextData *contextData = (Http3ContextData *) us_quic_socket_context_ext(us_quic_socket_context(us_quic_stream_socket(s)));
75
+
76
+ Http3Request *req = nullptr;
77
+
78
+ std::string_view upperCasedMethod = req->getHeader(":method");
79
+ std::string_view path = req->getHeader(":path");
80
+
81
+ contextData->router.getUserData() = {(Http3Response *) s, (Http3Request *) nullptr};
82
+ contextData->router.route(upperCasedMethod, path);
83
+
84
+ });
85
+ us_quic_socket_context_on_open(context, [](us_quic_socket_t *s, int is_client) {
86
+ printf("QUIC socket connected!\n");
87
+ });
88
+ us_quic_socket_context_on_stream_close(context, [](us_quic_stream_t *s) {
89
+
90
+ printf("Stream closed!\n");
91
+
92
+ //lsquic_stream_has_unacked_data
93
+
94
+ Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s);
95
+
96
+ if (responseData->onAborted) {
97
+ responseData->onAborted();
98
+ }
99
+
100
+ //printf("Freeing per stream data in on_stream_close in uws!\n");
101
+
102
+ responseData->~Http3ResponseData();
103
+ });
104
+
105
+ return (Http3Context *) context;
106
+
107
+ // call init here after setting the ext to Http3ContextData
108
+ }
109
+
110
+ us_quic_listen_socket_t *listen(const char *host, int port) {
111
+ /* The listening socket is the actual UDP socket used */
112
+ us_quic_listen_socket_t *listen_socket = us_quic_socket_context_listen((us_quic_socket_context_t *) this, host, port, sizeof(Http3ResponseData));
113
+
114
+ //printf("Listen socket is: %p\n", listen_socket);
115
+
116
+ return listen_socket;
117
+ }
118
+
119
+ void init() {
120
+ // set all callbacks here
121
+
122
+
123
+
124
+ Http3ContextData *contextData = (Http3ContextData *) us_quic_socket_context_ext((us_quic_socket_context_t *) this);
125
+
126
+ //printf("init: %p\n", contextData);
127
+
128
+ new (contextData) Http3ContextData();
129
+
130
+ }
131
+
132
+ // generic for get, post, any, etc
133
+ void onHttp(std::string method, std::string path, MoveOnlyFunction<void(Http3Response *, Http3Request *)> &&cb) {
134
+ // modifies the router we own as part of Http3ContextData, used in callbacks set in init
135
+
136
+ Http3ContextData *contextData = (Http3ContextData *) us_quic_socket_context_ext((us_quic_socket_context_t *) this);
137
+
138
+ /* Todo: This is ugly, fix */
139
+ std::vector<std::string> methods;
140
+ if (method == "*") {
141
+ methods = {"*"}; //bug! needs to be upper cased!
142
+ // router.upperCasedMethods;
143
+ } else {
144
+ methods = {method};
145
+ }
146
+
147
+ contextData->router.add(methods, path, [handler = std::move(cb)](HttpRouter<Http3ContextData::RouterData> *router) mutable {
148
+
149
+ Http3ContextData::RouterData &routerData = router->getUserData();
150
+
151
+ handler(routerData.res, routerData.req);
152
+
153
+ return true;
154
+ });
155
+ }
156
+ };
157
+ }
@@ -0,0 +1,21 @@
1
+ #include "HttpRouter.h"
2
+
3
+ struct Http3Response;
4
+ struct Http3Request;
5
+
6
+ namespace uWS {
7
+
8
+ struct Http3ContextData {
9
+ struct RouterData {
10
+ Http3Response *res;
11
+ Http3Request *req;
12
+ };
13
+
14
+ HttpRouter<RouterData> router;
15
+
16
+ Http3ContextData() {
17
+ //printf("Constructing http3contextdata: %p\n", this);
18
+ }
19
+ };
20
+
21
+ }
@@ -0,0 +1,22 @@
1
+ extern "C" {
2
+ #include "quic.h"
3
+ }
4
+
5
+ namespace uWS {
6
+
7
+ struct Http3Request {
8
+
9
+ std::string_view getHeader(std::string_view key) {
10
+ for (int i = 0, more = 1; more; i++) {
11
+ char *name, *value;
12
+ int name_length, value_length;
13
+ if ((more = us_quic_socket_context_get_header(nullptr, i, &name, &name_length, &value, &value_length))) {
14
+ if (name_length == (int) key.length() && !memcmp(name, key.data(), key.length())) {
15
+ return {value, (size_t) value_length};
16
+ }
17
+ }
18
+ }
19
+ return {nullptr, 0};
20
+ }
21
+ };
22
+ }