@dooboostore/simple-boot-http-server 1.0.19 → 1.0.21

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 (288) hide show
  1. package/README.MD +24 -248
  2. package/dist/cjs/SimpleBootHttpServer.js +2 -4
  3. package/dist/cjs/SimpleBootHttpServer.js.map +2 -2
  4. package/dist/cjs/bundle-entry.js +44 -0
  5. package/dist/cjs/bundle-entry.js.map +7 -0
  6. package/dist/cjs/codes/HttpHeaders.js +42 -42
  7. package/dist/cjs/codes/HttpHeaders.js.map +3 -3
  8. package/dist/cjs/errors/HttpError.js +1 -5
  9. package/dist/cjs/errors/HttpError.js.map +1 -1
  10. package/dist/cjs/filters/CacheFilter.js +4 -3
  11. package/dist/cjs/filters/CacheFilter.js.map +1 -1
  12. package/dist/cjs/filters/OpenApi3Filter.js +0 -1
  13. package/dist/cjs/filters/OpenApi3Filter.js.map +1 -1
  14. package/dist/cjs/index.js.map +2 -2
  15. package/dist/cjs/models/RequestResponse.js +0 -5
  16. package/dist/cjs/models/RequestResponse.js.map +2 -2
  17. package/dist/cjs/models/datas/ReqHeader.js +0 -63
  18. package/dist/cjs/models/datas/ReqHeader.js.map +1 -1
  19. package/dist/cjs/option/HttpServerOption.js +6 -13
  20. package/dist/cjs/option/HttpServerOption.js.map +1 -1
  21. package/dist/cjs/package.json +2 -0
  22. package/dist/cjs/session/SessionManager.js +1 -2
  23. package/dist/cjs/session/SessionManager.js.map +1 -1
  24. package/dist/esm/SimpleBootHttpServer.js +2 -4
  25. package/dist/esm/SimpleBootHttpServer.js.map +2 -2
  26. package/dist/esm/bundle-entry.js +13 -0
  27. package/dist/esm/bundle-entry.js.map +7 -0
  28. package/dist/esm/codes/HttpHeaders.js +42 -42
  29. package/dist/esm/codes/HttpHeaders.js.map +3 -3
  30. package/dist/esm/errors/HttpError.js +1 -5
  31. package/dist/esm/errors/HttpError.js.map +1 -1
  32. package/dist/esm/filters/CacheFilter.js +4 -3
  33. package/dist/esm/filters/CacheFilter.js.map +1 -1
  34. package/dist/esm/filters/OpenApi3Filter.js +0 -1
  35. package/dist/esm/filters/OpenApi3Filter.js.map +1 -1
  36. package/dist/esm/index.js.map +2 -2
  37. package/dist/esm/models/RequestResponse.js +0 -5
  38. package/dist/esm/models/RequestResponse.js.map +2 -2
  39. package/dist/esm/models/datas/ReqHeader.js +0 -63
  40. package/dist/esm/models/datas/ReqHeader.js.map +1 -1
  41. package/dist/esm/option/HttpServerOption.js +6 -13
  42. package/dist/esm/option/HttpServerOption.js.map +1 -1
  43. package/dist/esm/session/SessionManager.js +1 -2
  44. package/dist/esm/session/SessionManager.js.map +1 -1
  45. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +15391 -3
  46. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
  47. package/dist/{cjs → types}/SimpleBootHttpServer.d.ts +1 -2
  48. package/dist/types/SimpleBootHttpServer.d.ts.map +1 -0
  49. package/dist/types/bundle-entry.d.ts +13 -0
  50. package/dist/types/bundle-entry.d.ts.map +1 -0
  51. package/dist/types/codes/HttpHeaders.d.ts +43 -0
  52. package/dist/types/codes/HttpHeaders.d.ts.map +1 -0
  53. package/dist/types/index.d.ts +41 -0
  54. package/dist/{esm → types}/index.d.ts.map +1 -1
  55. package/dist/{esm → types}/models/RequestResponse.d.ts +7 -7
  56. package/dist/types/models/RequestResponse.d.ts.map +1 -0
  57. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +15384 -7
  58. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
  59. package/package.json +28 -16
  60. package/src/SimpleBootHttpServer.ts +329 -0
  61. package/src/bundle-entry.ts +12 -0
  62. package/src/codes/HttpHeaders.ts +43 -0
  63. package/src/codes/HttpMethod.ts +11 -0
  64. package/{dist/esm/codes/HttpStatus.d.ts → src/codes/HttpStatus.ts} +2 -2
  65. package/src/codes/Mimes.ts +27 -0
  66. package/{dist/esm/codes/index.d.ts → src/codes/index.ts} +0 -1
  67. package/src/decorators/MethodMapping.ts +233 -0
  68. package/src/decorators/index.ts +1 -0
  69. package/src/endpoints/CrossDomainHeaderEndPoint.ts +38 -0
  70. package/src/endpoints/EndPoint.ts +7 -0
  71. package/src/endpoints/HeaderEndPoint.ts +17 -0
  72. package/{dist/esm/endpoints/index.d.ts → src/endpoints/index.ts} +0 -1
  73. package/src/errors/BadRequestError.ts +8 -0
  74. package/src/errors/ForbiddenError.ts +8 -0
  75. package/src/errors/HttpError.ts +14 -0
  76. package/src/errors/InternalServerError.ts +8 -0
  77. package/src/errors/NotFoundError.ts +8 -0
  78. package/src/errors/UnauthorizedError.ts +8 -0
  79. package/{dist/esm/errors/index.d.ts → src/errors/index.ts} +0 -1
  80. package/src/filters/CacheFilter.ts +169 -0
  81. package/src/filters/Filter.ts +10 -0
  82. package/src/filters/HttpStatusFilter.ts +24 -0
  83. package/src/filters/OpenApi3Filter.ts +158 -0
  84. package/src/filters/ResourceFilter.ts +72 -0
  85. package/src/filters/ThrowFilter.ts +23 -0
  86. package/{dist/esm/filters/index.d.ts → src/filters/index.ts} +0 -1
  87. package/src/index.ts +13 -0
  88. package/src/inject/InjectSituationType.ts +3 -0
  89. package/{dist/esm/inject/index.d.ts → src/inject/index.ts} +0 -1
  90. package/src/lifecycle/OnInit.ts +5 -0
  91. package/src/lifecycle/index.ts +1 -0
  92. package/src/models/RequestResponse.ts +658 -0
  93. package/src/models/datas/HeaderData.ts +4 -0
  94. package/src/models/datas/MultipartData.ts +27 -0
  95. package/{dist/esm/models/datas/ReqHeader.d.ts → src/models/datas/ReqHeader.ts} +5 -4
  96. package/src/models/datas/Resource.ts +44 -0
  97. package/src/models/datas/body/ReqFormUrlBody.ts +3 -0
  98. package/src/models/datas/body/ReqJsonBody.ts +3 -0
  99. package/src/models/datas/body/ReqMultipartFormBody.ts +6 -0
  100. package/{dist/esm/models/index.d.ts → src/models/index.ts} +0 -1
  101. package/src/models/method/patch/PatchJson.ts +46 -0
  102. package/src/option/HttpServerOption.ts +81 -0
  103. package/{dist/esm/option/index.d.ts → src/option/index.ts} +0 -1
  104. package/src/resolvers/Resolver.ts +5 -0
  105. package/src/resolvers/ResourceResolver.ts +11 -0
  106. package/{dist/esm/resolvers/index.d.ts → src/resolvers/index.ts} +0 -1
  107. package/src/session/SessionManager.ts +89 -0
  108. package/src/session/index.ts +1 -0
  109. package/tsconfig.json +23 -0
  110. package/dist/cjs/SimpleBootHttpServer.d.ts.map +0 -1
  111. package/dist/cjs/codes/HttpHeaders.d.ts +0 -42
  112. package/dist/cjs/codes/HttpHeaders.d.ts.map +0 -1
  113. package/dist/cjs/index.d.ts +0 -3
  114. package/dist/cjs/index.d.ts.map +0 -1
  115. package/dist/cjs/models/RequestResponse.d.ts +0 -100
  116. package/dist/cjs/models/RequestResponse.d.ts.map +0 -1
  117. package/dist/esm/SimpleBootHttpServer.d.ts +0 -15
  118. package/dist/esm/SimpleBootHttpServer.d.ts.map +0 -1
  119. package/dist/esm/codes/HttpHeaders.d.ts +0 -42
  120. package/dist/esm/codes/HttpHeaders.d.ts.map +0 -1
  121. package/dist/esm/codes/HttpMethod.d.ts +0 -12
  122. package/dist/esm/codes/HttpMethod.d.ts.map +0 -1
  123. package/dist/esm/codes/HttpStatus.d.ts.map +0 -1
  124. package/dist/esm/codes/Mimes.d.ts +0 -28
  125. package/dist/esm/codes/Mimes.d.ts.map +0 -1
  126. package/dist/esm/codes/index.d.ts.map +0 -1
  127. package/dist/esm/decorators/MethodMapping.d.ts +0 -73
  128. package/dist/esm/decorators/MethodMapping.d.ts.map +0 -1
  129. package/dist/esm/decorators/index.d.ts +0 -2
  130. package/dist/esm/decorators/index.d.ts.map +0 -1
  131. package/dist/esm/endpoints/CrossDomainHeaderEndPoint.d.ts +0 -16
  132. package/dist/esm/endpoints/CrossDomainHeaderEndPoint.d.ts.map +0 -1
  133. package/dist/esm/endpoints/EndPoint.d.ts +0 -7
  134. package/dist/esm/endpoints/EndPoint.d.ts.map +0 -1
  135. package/dist/esm/endpoints/HeaderEndPoint.d.ts +0 -12
  136. package/dist/esm/endpoints/HeaderEndPoint.d.ts.map +0 -1
  137. package/dist/esm/endpoints/index.d.ts.map +0 -1
  138. package/dist/esm/errors/BadRequestError.d.ts +0 -8
  139. package/dist/esm/errors/BadRequestError.d.ts.map +0 -1
  140. package/dist/esm/errors/ForbiddenError.d.ts +0 -8
  141. package/dist/esm/errors/ForbiddenError.d.ts.map +0 -1
  142. package/dist/esm/errors/HttpError.d.ts +0 -12
  143. package/dist/esm/errors/HttpError.d.ts.map +0 -1
  144. package/dist/esm/errors/InternalServerError.d.ts +0 -8
  145. package/dist/esm/errors/InternalServerError.d.ts.map +0 -1
  146. package/dist/esm/errors/NotFoundError.d.ts +0 -8
  147. package/dist/esm/errors/NotFoundError.d.ts.map +0 -1
  148. package/dist/esm/errors/UnauthorizedError.d.ts +0 -8
  149. package/dist/esm/errors/UnauthorizedError.d.ts.map +0 -1
  150. package/dist/esm/errors/index.d.ts.map +0 -1
  151. package/dist/esm/filters/CacheFilter.d.ts +0 -45
  152. package/dist/esm/filters/CacheFilter.d.ts.map +0 -1
  153. package/dist/esm/filters/Filter.d.ts +0 -17
  154. package/dist/esm/filters/Filter.d.ts.map +0 -1
  155. package/dist/esm/filters/HttpStatusFilter.d.ts +0 -20
  156. package/dist/esm/filters/HttpStatusFilter.d.ts.map +0 -1
  157. package/dist/esm/filters/OpenApi3Filter.d.ts +0 -142
  158. package/dist/esm/filters/OpenApi3Filter.d.ts.map +0 -1
  159. package/dist/esm/filters/ResourceFilter.d.ts +0 -24
  160. package/dist/esm/filters/ResourceFilter.d.ts.map +0 -1
  161. package/dist/esm/filters/ThrowFilter.d.ts +0 -19
  162. package/dist/esm/filters/ThrowFilter.d.ts.map +0 -1
  163. package/dist/esm/filters/index.d.ts.map +0 -1
  164. package/dist/esm/index.d.ts +0 -3
  165. package/dist/esm/inject/InjectSituationType.d.ts +0 -4
  166. package/dist/esm/inject/InjectSituationType.d.ts.map +0 -1
  167. package/dist/esm/inject/index.d.ts.map +0 -1
  168. package/dist/esm/lifecycle/OnInit.d.ts +0 -5
  169. package/dist/esm/lifecycle/OnInit.d.ts.map +0 -1
  170. package/dist/esm/lifecycle/index.d.ts +0 -2
  171. package/dist/esm/lifecycle/index.d.ts.map +0 -1
  172. package/dist/esm/models/RequestResponse.d.ts.map +0 -1
  173. package/dist/esm/models/datas/HeaderData.d.ts +0 -10
  174. package/dist/esm/models/datas/HeaderData.d.ts.map +0 -1
  175. package/dist/esm/models/datas/MultipartData.d.ts +0 -12
  176. package/dist/esm/models/datas/MultipartData.d.ts.map +0 -1
  177. package/dist/esm/models/datas/ReqHeader.d.ts.map +0 -1
  178. package/dist/esm/models/datas/Resource.d.ts +0 -11
  179. package/dist/esm/models/datas/Resource.d.ts.map +0 -1
  180. package/dist/esm/models/datas/body/ReqFormUrlBody.d.ts +0 -4
  181. package/dist/esm/models/datas/body/ReqFormUrlBody.d.ts.map +0 -1
  182. package/dist/esm/models/datas/body/ReqJsonBody.d.ts +0 -4
  183. package/dist/esm/models/datas/body/ReqJsonBody.d.ts.map +0 -1
  184. package/dist/esm/models/datas/body/ReqMultipartFormBody.d.ts +0 -6
  185. package/dist/esm/models/datas/body/ReqMultipartFormBody.d.ts.map +0 -1
  186. package/dist/esm/models/index.d.ts.map +0 -1
  187. package/dist/esm/models/method/patch/PatchJson.d.ts +0 -8
  188. package/dist/esm/models/method/patch/PatchJson.d.ts.map +0 -1
  189. package/dist/esm/option/HttpServerOption.d.ts +0 -83
  190. package/dist/esm/option/HttpServerOption.d.ts.map +0 -1
  191. package/dist/esm/option/index.d.ts.map +0 -1
  192. package/dist/esm/resolvers/Resolver.d.ts +0 -5
  193. package/dist/esm/resolvers/Resolver.d.ts.map +0 -1
  194. package/dist/esm/resolvers/ResourceResolver.d.ts +0 -6
  195. package/dist/esm/resolvers/ResourceResolver.d.ts.map +0 -1
  196. package/dist/esm/resolvers/index.d.ts.map +0 -1
  197. package/dist/esm/session/SessionManager.d.ts +0 -57
  198. package/dist/esm/session/SessionManager.d.ts.map +0 -1
  199. package/dist/esm/session/index.d.ts +0 -2
  200. package/dist/esm/session/index.d.ts.map +0 -1
  201. /package/dist/{cjs → types}/codes/HttpMethod.d.ts +0 -0
  202. /package/dist/{cjs → types}/codes/HttpMethod.d.ts.map +0 -0
  203. /package/dist/{cjs → types}/codes/HttpStatus.d.ts +0 -0
  204. /package/dist/{cjs → types}/codes/HttpStatus.d.ts.map +0 -0
  205. /package/dist/{cjs → types}/codes/Mimes.d.ts +0 -0
  206. /package/dist/{cjs → types}/codes/Mimes.d.ts.map +0 -0
  207. /package/dist/{cjs → types}/codes/index.d.ts +0 -0
  208. /package/dist/{cjs → types}/codes/index.d.ts.map +0 -0
  209. /package/dist/{cjs → types}/decorators/MethodMapping.d.ts +0 -0
  210. /package/dist/{cjs → types}/decorators/MethodMapping.d.ts.map +0 -0
  211. /package/dist/{cjs → types}/decorators/index.d.ts +0 -0
  212. /package/dist/{cjs → types}/decorators/index.d.ts.map +0 -0
  213. /package/dist/{cjs → types}/endpoints/CrossDomainHeaderEndPoint.d.ts +0 -0
  214. /package/dist/{cjs → types}/endpoints/CrossDomainHeaderEndPoint.d.ts.map +0 -0
  215. /package/dist/{cjs → types}/endpoints/EndPoint.d.ts +0 -0
  216. /package/dist/{cjs → types}/endpoints/EndPoint.d.ts.map +0 -0
  217. /package/dist/{cjs → types}/endpoints/HeaderEndPoint.d.ts +0 -0
  218. /package/dist/{cjs → types}/endpoints/HeaderEndPoint.d.ts.map +0 -0
  219. /package/dist/{cjs → types}/endpoints/index.d.ts +0 -0
  220. /package/dist/{cjs → types}/endpoints/index.d.ts.map +0 -0
  221. /package/dist/{cjs → types}/errors/BadRequestError.d.ts +0 -0
  222. /package/dist/{cjs → types}/errors/BadRequestError.d.ts.map +0 -0
  223. /package/dist/{cjs → types}/errors/ForbiddenError.d.ts +0 -0
  224. /package/dist/{cjs → types}/errors/ForbiddenError.d.ts.map +0 -0
  225. /package/dist/{cjs → types}/errors/HttpError.d.ts +0 -0
  226. /package/dist/{cjs → types}/errors/HttpError.d.ts.map +0 -0
  227. /package/dist/{cjs → types}/errors/InternalServerError.d.ts +0 -0
  228. /package/dist/{cjs → types}/errors/InternalServerError.d.ts.map +0 -0
  229. /package/dist/{cjs → types}/errors/NotFoundError.d.ts +0 -0
  230. /package/dist/{cjs → types}/errors/NotFoundError.d.ts.map +0 -0
  231. /package/dist/{cjs → types}/errors/UnauthorizedError.d.ts +0 -0
  232. /package/dist/{cjs → types}/errors/UnauthorizedError.d.ts.map +0 -0
  233. /package/dist/{cjs → types}/errors/index.d.ts +0 -0
  234. /package/dist/{cjs → types}/errors/index.d.ts.map +0 -0
  235. /package/dist/{cjs → types}/filters/CacheFilter.d.ts +0 -0
  236. /package/dist/{cjs → types}/filters/CacheFilter.d.ts.map +0 -0
  237. /package/dist/{cjs → types}/filters/Filter.d.ts +0 -0
  238. /package/dist/{cjs → types}/filters/Filter.d.ts.map +0 -0
  239. /package/dist/{cjs → types}/filters/HttpStatusFilter.d.ts +0 -0
  240. /package/dist/{cjs → types}/filters/HttpStatusFilter.d.ts.map +0 -0
  241. /package/dist/{cjs → types}/filters/OpenApi3Filter.d.ts +0 -0
  242. /package/dist/{cjs → types}/filters/OpenApi3Filter.d.ts.map +0 -0
  243. /package/dist/{cjs → types}/filters/ResourceFilter.d.ts +0 -0
  244. /package/dist/{cjs → types}/filters/ResourceFilter.d.ts.map +0 -0
  245. /package/dist/{cjs → types}/filters/ThrowFilter.d.ts +0 -0
  246. /package/dist/{cjs → types}/filters/ThrowFilter.d.ts.map +0 -0
  247. /package/dist/{cjs → types}/filters/index.d.ts +0 -0
  248. /package/dist/{cjs → types}/filters/index.d.ts.map +0 -0
  249. /package/dist/{cjs → types}/inject/InjectSituationType.d.ts +0 -0
  250. /package/dist/{cjs → types}/inject/InjectSituationType.d.ts.map +0 -0
  251. /package/dist/{cjs → types}/inject/index.d.ts +0 -0
  252. /package/dist/{cjs → types}/inject/index.d.ts.map +0 -0
  253. /package/dist/{cjs → types}/lifecycle/OnInit.d.ts +0 -0
  254. /package/dist/{cjs → types}/lifecycle/OnInit.d.ts.map +0 -0
  255. /package/dist/{cjs → types}/lifecycle/index.d.ts +0 -0
  256. /package/dist/{cjs → types}/lifecycle/index.d.ts.map +0 -0
  257. /package/dist/{cjs → types}/models/datas/HeaderData.d.ts +0 -0
  258. /package/dist/{cjs → types}/models/datas/HeaderData.d.ts.map +0 -0
  259. /package/dist/{cjs → types}/models/datas/MultipartData.d.ts +0 -0
  260. /package/dist/{cjs → types}/models/datas/MultipartData.d.ts.map +0 -0
  261. /package/dist/{cjs → types}/models/datas/ReqHeader.d.ts +0 -0
  262. /package/dist/{cjs → types}/models/datas/ReqHeader.d.ts.map +0 -0
  263. /package/dist/{cjs → types}/models/datas/Resource.d.ts +0 -0
  264. /package/dist/{cjs → types}/models/datas/Resource.d.ts.map +0 -0
  265. /package/dist/{cjs → types}/models/datas/body/ReqFormUrlBody.d.ts +0 -0
  266. /package/dist/{cjs → types}/models/datas/body/ReqFormUrlBody.d.ts.map +0 -0
  267. /package/dist/{cjs → types}/models/datas/body/ReqJsonBody.d.ts +0 -0
  268. /package/dist/{cjs → types}/models/datas/body/ReqJsonBody.d.ts.map +0 -0
  269. /package/dist/{cjs → types}/models/datas/body/ReqMultipartFormBody.d.ts +0 -0
  270. /package/dist/{cjs → types}/models/datas/body/ReqMultipartFormBody.d.ts.map +0 -0
  271. /package/dist/{cjs → types}/models/index.d.ts +0 -0
  272. /package/dist/{cjs → types}/models/index.d.ts.map +0 -0
  273. /package/dist/{cjs → types}/models/method/patch/PatchJson.d.ts +0 -0
  274. /package/dist/{cjs → types}/models/method/patch/PatchJson.d.ts.map +0 -0
  275. /package/dist/{cjs → types}/option/HttpServerOption.d.ts +0 -0
  276. /package/dist/{cjs → types}/option/HttpServerOption.d.ts.map +0 -0
  277. /package/dist/{cjs → types}/option/index.d.ts +0 -0
  278. /package/dist/{cjs → types}/option/index.d.ts.map +0 -0
  279. /package/dist/{cjs → types}/resolvers/Resolver.d.ts +0 -0
  280. /package/dist/{cjs → types}/resolvers/Resolver.d.ts.map +0 -0
  281. /package/dist/{cjs → types}/resolvers/ResourceResolver.d.ts +0 -0
  282. /package/dist/{cjs → types}/resolvers/ResourceResolver.d.ts.map +0 -0
  283. /package/dist/{cjs → types}/resolvers/index.d.ts +0 -0
  284. /package/dist/{cjs → types}/resolvers/index.d.ts.map +0 -0
  285. /package/dist/{cjs → types}/session/SessionManager.d.ts +0 -0
  286. /package/dist/{cjs → types}/session/SessionManager.d.ts.map +0 -0
  287. /package/dist/{cjs → types}/session/index.d.ts +0 -0
  288. /package/dist/{cjs → types}/session/index.d.ts.map +0 -0
@@ -0,0 +1,658 @@
1
+ import { IncomingMessage, OutgoingHttpHeader, OutgoingHttpHeaders, ServerResponse } from 'http';
2
+ import { HttpHeaders, HttpHeadersType } from '../codes/HttpHeaders';
3
+ import { Mimes } from '../codes/Mimes';
4
+ import { Intent } from '@dooboostore/simple-boot/intent/Intent';
5
+ import { URL, URLSearchParams } from 'url';
6
+ import { Buffer } from 'buffer';
7
+ import { MultipartData } from './datas/MultipartData';
8
+ import { ReqFormUrlBody } from './datas/body/ReqFormUrlBody';
9
+ import { ReqJsonBody } from './datas/body/ReqJsonBody';
10
+ import { ReqHeader } from './datas/ReqHeader';
11
+ import { ReqMultipartFormBody } from './datas/body/ReqMultipartFormBody';
12
+ import { HttpStatus } from '../codes/HttpStatus';
13
+ import { gzip } from 'node-gzip';
14
+ import { SessionManager } from '../session/SessionManager';
15
+ import { HttpServerOption } from '../option/HttpServerOption';
16
+ import * as fs from 'fs';
17
+ import * as os from 'os';
18
+ import { RandomUtils } from '@dooboostore/core/random/RandomUtils';
19
+ import { FileUtils } from '@dooboostore/core-node/file/FileUtils';
20
+ import { ConvertUtils as CoreConvertUtils} from '@dooboostore/core/convert/ConvertUtils';
21
+ import { ConvertUtils } from '@dooboostore/core-node/convert/ConvertUtils';
22
+ // https://masteringjs.io/tutorials/node/http-request
23
+ type Config = { sessionManager?: SessionManager, option: HttpServerOption };
24
+
25
+ // https://nodejs.org/ko/docs/guides/anatomy-of-an-http-transaction/
26
+ export class RequestResponse {
27
+ protected resWriteChunk: string | Buffer | undefined;
28
+ protected reqBodyChunk?: Buffer;
29
+ protected req: IncomingMessage;
30
+ protected res: ServerResponse;
31
+ protected config: Config;
32
+ // protected sessionManager?: SessionManager;
33
+
34
+ // constructor(req: IncomingMessage, res: ServerResponse);
35
+ // constructor(req: RequestResponse);
36
+ // constructor(req: IncomingMessage, res: ServerResponse, sessionManager?: SessionManager);
37
+ // constructor(req: IncomingMessage | RequestResponse, res?: ServerResponse, sessionManager?: SessionManager) {
38
+ // // this.req = req;
39
+ // // this.res = res;
40
+ // if (req instanceof RequestResponse) {
41
+ // this.req = req.req;
42
+ // this.res = req.res;
43
+ // this.sessionManager = req.sessionManager;
44
+ // } else {
45
+ // this.req = req;
46
+ // this.res = res!;
47
+ // this.sessionManager = sessionManager;
48
+ // }
49
+ // }
50
+ constructor(req: IncomingMessage | RequestResponse, res: ServerResponse, config: Config) {
51
+ // this.req = req;
52
+ // this.res = res;
53
+ if (req instanceof RequestResponse) {
54
+ this.req = req.req;
55
+ this.res = req.res;
56
+ this.config = config;
57
+ } else {
58
+ this.req = req;
59
+ this.res = res!;
60
+ this.config = config;
61
+ }
62
+ }
63
+
64
+ get reqSocket() {
65
+ return this.req.socket;
66
+ }
67
+
68
+ get reqCookieMap() {
69
+ let cookies = this.reqHeader(HttpHeaders.Cookie) ?? '';
70
+ if (Array.isArray(cookies)) {
71
+ cookies = cookies.join(';')
72
+ }
73
+
74
+ const map = new Map<string, string>();
75
+ cookies.split(';').map(it => it.trim().split('=')).forEach(it => {
76
+ map.set(it[0], it[1]);
77
+ });
78
+ return map;
79
+ }
80
+
81
+ reqCookieGet(key: string) {
82
+ return this.reqCookieMap.get(key);
83
+ }
84
+
85
+ get reqRemoteAddress(): string | undefined {
86
+ const ipHeader = this.req.headers['x-forwarded-for'];
87
+ let ip = this.req.socket.remoteAddress;
88
+ if (Array.isArray(ipHeader)) {
89
+ ip = ipHeader.join(',').split(',').shift();
90
+ } else if (typeof ipHeader === 'string') {
91
+ ip = ipHeader.split(',').shift();
92
+ }
93
+ return ip;
94
+ }
95
+
96
+ get reqUrlObject(): URL {
97
+ return new URL(this.reqUrl, `${this.reqSocket ? 'https://' : 'http'}${this.reqHost ?? 'localhost'}`);
98
+ }
99
+
100
+ get reqUrlPathName(): string {
101
+ // parse(rr.reqUrl ?? '', true)
102
+ return this.reqUrlObj().pathname ?? '';
103
+ }
104
+
105
+ get reqUrl(): string {
106
+ return this.req.url ?? '';
107
+ }
108
+
109
+ reqUrlObj(config?:{scheme?: string, host?: string}): URL {
110
+ return new URL(`${config?.scheme??'http' }://${config?.host ? config?.host : (this.reqHeaderFirst(HttpHeaders.Host) ?? 'localhost')}${this.req.url ?? ''}`);
111
+ }
112
+
113
+ get reqUrlSearchParamTuples(): [string, string][] {
114
+ return Array.from(this.reqUrlObj().searchParams as any);
115
+ }
116
+
117
+ get reqUrlSearchParams(): URLSearchParams {
118
+ return this.reqUrlObj().searchParams;
119
+ }
120
+
121
+ get reqUrlSearchParamsObj(): {[p: string]: string | string[]} {
122
+ const entries = this.reqUrlObj().searchParams;
123
+ return CoreConvertUtils.toObject(entries);
124
+ // return obj;
125
+ // return Object.fromEntries(entries as any)
126
+ }
127
+
128
+ get reqPathSearchParamUrl(): string {
129
+ const reqUrlObj = this.reqUrlObj();
130
+ return reqUrlObj.pathname + (reqUrlObj.searchParams.toString() ? '?' + reqUrlObj.searchParams.toString() : '')
131
+ }
132
+
133
+ get reqReadable() {
134
+ return this.req.readable;
135
+ }
136
+
137
+ get reqIntent() {
138
+ return new Intent(this.reqPathSearchParamUrl);
139
+ }
140
+
141
+ reqHasContentTypeHeader(mime: Mimes | string): boolean {
142
+ return (this.reqHeaderFirst(HttpHeaders.ContentType) ?? '').toLowerCase().indexOf(mime.toLocaleLowerCase()) > -1;
143
+ }
144
+
145
+ reqHasAcceptHeader(mime: Mimes | string): boolean {
146
+ return (this.reqHeaderFirst(HttpHeaders.Accept) ?? '').toLowerCase().indexOf(mime.toLocaleLowerCase()) > -1;
147
+ }
148
+
149
+ reqBodyData(): Promise<Buffer> {
150
+ return new Promise<Buffer>((resolve, reject) => {
151
+ if (this.reqReadable) {
152
+ const data: Uint8Array[] = [];
153
+ this.req.on('data', (chunk) => data.push(chunk));
154
+ this.req.on('error', err => reject(err));
155
+ this.req.on('end', () => {
156
+ this.reqBodyChunk = Buffer.concat(data);
157
+ resolve(this.reqBodyChunk);
158
+ });
159
+ } else {
160
+ resolve(this.reqBodyChunk ?? Buffer.alloc(0));
161
+ }
162
+ });
163
+ }
164
+
165
+ resBodyData(): string | Buffer | undefined{
166
+ return this.resWriteChunk;
167
+ }
168
+
169
+
170
+
171
+ async reqBodyMultipartFormDataObject<T>(): Promise<T> {
172
+ const m = await this.reqBodyMultipartFormData();
173
+ const formData = {} as any;
174
+
175
+ for (const it of m) {
176
+ if (it.isFile) {
177
+ formData[it.name] = await FileUtils.writeFile(it.value, {originalName: it.filename });
178
+ } else {
179
+ const target = formData[it.name];
180
+ if (Array.isArray(target)) {
181
+ target.push(it.value);
182
+ } else if (typeof target === 'string') {
183
+ formData[it.name] = [target, it.value]
184
+ } else {
185
+ formData[it.name] = it.value;
186
+ }
187
+ }
188
+ };
189
+ return formData;
190
+ }
191
+
192
+ reqBodyMultipartFormData(): Promise<MultipartData[]> {
193
+ return new Promise((resolve, reject) => {
194
+ const contentTypeHeader = this.req.headers['content-type'];
195
+ if (!contentTypeHeader || !contentTypeHeader.startsWith('multipart/form-data')) {
196
+ return reject(new Error('Invalid Content-Type. Expected multipart/form-data.'));
197
+ }
198
+
199
+ const boundaryMatch = contentTypeHeader.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
200
+ if (!boundaryMatch) {
201
+ return reject(new Error('Boundary not found in Content-Type header.'));
202
+ }
203
+ const boundary = boundaryMatch[1] || boundaryMatch[2]; // 따옴표 유무 처리
204
+ if (!boundary) {
205
+ return reject(new Error('Failed to extract boundary.'));
206
+ }
207
+
208
+ const boundaryBuffer = Buffer.from(`--${boundary}`);
209
+ const crlfBuffer = Buffer.from('\r\n');
210
+ const doubleCrlfBuffer = Buffer.from('\r\n\r\n'); // 헤더와 바디 구분자
211
+
212
+ const chunks: Buffer[] = [];
213
+ let totalLength = 0;
214
+
215
+ this.req.on('data', (chunk: Buffer) => {
216
+ chunks.push(chunk);
217
+ totalLength += chunk.length;
218
+ });
219
+
220
+ this.req.on('error', (err) => {
221
+ reject(err);
222
+ });
223
+
224
+ this.req.on('end', () => {
225
+ if (totalLength === 0) {
226
+ return resolve([]); // 빈 요청 처리
227
+ }
228
+
229
+ const fullBuffer = Buffer.concat(chunks, totalLength);
230
+ const parsedParts: MultipartData[] = [];
231
+ let currentPosition = 0;
232
+
233
+ // 첫 번째 boundary 찾기 (보통 시작 부분에 있음)
234
+ let boundaryStartIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
235
+ if (boundaryStartIndex === -1) {
236
+ return reject(new Error('Initial boundary not found.'));
237
+ }
238
+ // boundary 바로 다음 \r\n 건너뛰기
239
+ currentPosition = boundaryStartIndex + boundaryBuffer.length;
240
+ if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
241
+ currentPosition += crlfBuffer.length;
242
+ }
243
+
244
+
245
+ while (currentPosition < fullBuffer.length) {
246
+ // 다음 boundary 찾기 (파트의 끝)
247
+ const nextBoundaryIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
248
+ if (nextBoundaryIndex === -1) {
249
+ // 마지막 boundary (--)인지 확인 필요하나, 여기서는 단순하게 처리
250
+ // console.warn('Next boundary not found, assuming end of data or malformed.');
251
+ break;
252
+ }
253
+
254
+ // 현재 파트 데이터 추출 (boundary 이전까지)
255
+ // 실제 파트 데이터는 다음 boundary 바로 앞의 \r\n을 제외해야 함
256
+ let partEndIndex = nextBoundaryIndex;
257
+ if (partEndIndex > crlfBuffer.length && fullBuffer.slice(partEndIndex - crlfBuffer.length, partEndIndex).equals(crlfBuffer)) {
258
+ partEndIndex -= crlfBuffer.length;
259
+ }
260
+ const partBuffer = fullBuffer.slice(currentPosition, partEndIndex);
261
+
262
+ // 헤더와 바디 분리
263
+ const headerBodySeparatorIndex = partBuffer.indexOf(doubleCrlfBuffer);
264
+ if (headerBodySeparatorIndex === -1) {
265
+ console.warn('Skipping malformed part: no header/body separator found.');
266
+ currentPosition = nextBoundaryIndex + boundaryBuffer.length;
267
+ if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
268
+ currentPosition += crlfBuffer.length;
269
+ }
270
+ if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === '--') break; // 마지막 boundary
271
+ continue;
272
+ }
273
+
274
+ const headerBuffer = partBuffer.slice(0, headerBodySeparatorIndex);
275
+ const bodyBuffer = partBuffer.slice(headerBodySeparatorIndex + doubleCrlfBuffer.length);
276
+ const headersStr = headerBuffer.toString('utf-8'); // 헤더는 보통 ASCII/UTF-8
277
+
278
+ // 헤더 파싱
279
+ const headers: { [key: string]: string } = {};
280
+ headersStr.split('\r\n').forEach(line => {
281
+ const colonIndex = line.indexOf(':');
282
+ if (colonIndex > 0) {
283
+ const key = line.substring(0, colonIndex).trim().toLowerCase();
284
+ const value = line.substring(colonIndex + 1).trim();
285
+ headers[key] = value;
286
+ }
287
+ });
288
+
289
+ const contentDisposition = headers['content-disposition'];
290
+ if (!contentDisposition) {
291
+ console.warn('Skipping part: no Content-Disposition header.');
292
+ currentPosition = nextBoundaryIndex + boundaryBuffer.length;
293
+ if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
294
+ currentPosition += crlfBuffer.length;
295
+ }
296
+ if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === '--') break;
297
+ continue;
298
+ }
299
+
300
+ const nameMatch = contentDisposition.match(/name="([^"]+)"/i);
301
+ const filenameMatch = contentDisposition.match(/filename="([^"]+)"/i);
302
+
303
+ const name = nameMatch ? nameMatch[1] : null;
304
+ const filename = filenameMatch ? filenameMatch[1] : null;
305
+ const contentType = headers['content-type'] || null;
306
+
307
+ if (name) {
308
+
309
+ const isFile = !!filename;
310
+ // @ts-ignore
311
+ const multipartData:MultipartData = {
312
+ name:name,
313
+ isFile: isFile, // filename이 있으면 파일로 간주
314
+ filename: filename,
315
+ contentType: contentType,
316
+ value: isFile ? bodyBuffer: bodyBuffer.toString('utf-8'),
317
+ }
318
+ parsedParts.push(multipartData);
319
+ } else {
320
+ console.warn("Skipping part: 'name' not found in Content-Disposition.");
321
+ }
322
+
323
+ // 다음 파트 시작 위치로 이동
324
+ currentPosition = nextBoundaryIndex + boundaryBuffer.length;
325
+ // boundary 바로 다음 \r\n 건너뛰기
326
+ if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
327
+ currentPosition += crlfBuffer.length;
328
+ }
329
+
330
+ // 마지막 boundary (--)인지 확인하고 루프 종료
331
+ if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === '--') {
332
+ break;
333
+ }
334
+ }
335
+ resolve(parsedParts);
336
+ });
337
+ })
338
+ // const form = formidable({});
339
+ // return new Promise((resolve, reject) => {
340
+ // form.parse(this.req, (err, fields, files) => {
341
+ // if (err) {
342
+ // reject(err);
343
+ // return;
344
+ // }
345
+ //
346
+ // console.log('----', files)
347
+ // // this.res.set('Content-Type', 'application/json');
348
+ // // ctx.status = 200;
349
+ // // ctx.state = { fields, files };
350
+ // // ctx.body = JSON.stringify(ctx.state, null, 2);
351
+ // resolve(' ' as any);
352
+ // });
353
+ // });
354
+
355
+ // return new Promise<MultipartData<any>[]>((resolve, reject) => {
356
+ //
357
+ //
358
+ // const contentType = this.req.headers['content-type'];
359
+ // const boundary = contentType.split('boundary=')[1];
360
+ //
361
+ // let body: Uint8Array[] = [];
362
+ // this.req.on('data', chunk => body.push(chunk));
363
+ // this.req.on('end', async () => {
364
+ // const buffer = Buffer.concat(body);
365
+ // // Boundary로 파트 분리
366
+ // const parts = buffer.toString().split(`--${boundary}`).slice(1, -1);
367
+ // let jsonData = {};
368
+ // let fileData = null;
369
+ //
370
+ // for (let part of parts) {
371
+ // const [headerPart, ...bodyParts] = part.split('\r\n\r\n');
372
+ // const headers = headerPart.split('\r\n').reduce((acc, line) => {
373
+ // const [key, value] = line.split(': ').map(s => s.trim().toLowerCase());
374
+ // if (key) acc[key] = value;
375
+ // return acc;
376
+ // }, {});
377
+ //
378
+ // const content = bodyParts.join('\r\n\r\n').trim();
379
+ // const disposition = headers['content-disposition'];
380
+ // const name = disposition?.match(/name="([^"]+)"/)?.[1];
381
+ // const filename = disposition?.match(/filename="([^"]+)"/)?.[1];
382
+ //
383
+ // if (filename) {
384
+ // // 파일 데이터 (Blob)
385
+ // fileData = { filename, contentType: headers['content-type'], data: Buffer.from(content, 'binary') };
386
+ // } else if (name) {
387
+ // // 텍스트 데이터
388
+ // if (name === 'metadata') jsonData = JSON.parse(content);
389
+ // }
390
+ // }
391
+ //
392
+ // // 파일 저장
393
+ // if (fileData) {
394
+ //
395
+ //
396
+ //
397
+ //
398
+ // const uploadPath = this.config.option.fileUploadTempPath || os.tmpdir();
399
+ // fs.mkdirSync(uploadPath, { recursive: true }); // 폴더가 없으면 생성
400
+ // const saveTempPath = `${uploadPath}/${RandomUtils.uuid4()}${fileData.filename}`;
401
+ // console.log('saveTempPathsaveTempPath', saveTempPath)
402
+ // await fs.promises.writeFile(saveTempPath, fileData.data);
403
+ // this.res.writeHead(200, { 'Content-Type': 'application/json' });
404
+ // this.res.end(JSON.stringify({ message: '업로드 성공', jsonData, filename: fileData?.filename }));
405
+ // // const uploadPath = this.config.option.fileUploadTempPath ;
406
+ // // fs.mkdirSync(uploadPath, { recursive: true }); // 폴더가 없으면 생성
407
+ // // await fs.writeFile(`${uploadPath}/${fileData.filename}`, fileData.data);
408
+ // }
409
+ // });
410
+ // });
411
+ }
412
+
413
+ async reqBodyStringData(): Promise<string> {
414
+ const data = (await this.reqBodyData()).toString()
415
+ return data;
416
+ }
417
+
418
+ async reqBodyJsonData<T>(): Promise<T> {
419
+ return JSON.parse(await this.reqBodyStringData());
420
+ }
421
+
422
+ async reqBodyFormUrlData<T>(): Promise<T> {
423
+ const data = (await this.reqBodyStringData())
424
+ const formData = {} as any;
425
+ Array.from(new URLSearchParams(data).entries()).forEach(([k, v]) => {
426
+ const target = formData[k];
427
+ if (Array.isArray(target)) {
428
+ target.push(v);
429
+ } else if (typeof target === 'string') {
430
+ formData[k] = [target, v]
431
+ } else {
432
+ formData[k] = v;
433
+ }
434
+ });
435
+ return formData;
436
+ }
437
+
438
+ async reqBodyReqFormUrlBody() {
439
+ const data = await this.reqBodyFormUrlData()
440
+ return Object.assign(new ReqFormUrlBody(), data);
441
+ }
442
+
443
+ async reqBodyReqJsonBody(): Promise<ReqJsonBody> {
444
+ const data = (await this.reqBodyStringData());
445
+ return Object.assign(new ReqJsonBody(), data ? JSON.parse(data) : {})
446
+ }
447
+
448
+ // reqBodyReqMultipartFormBody(): Promise<ReqMultipartFormBody> {
449
+ // return this.reqBodyMultipartFormData().then(it => new ReqMultipartFormBody(it))
450
+ // }
451
+
452
+ resBodyJsonData<T>(): (T | null) {
453
+ const data = ConvertUtils.toString(this.resBodyData());
454
+ return data ? JSON.parse(data) : null;
455
+ }
456
+
457
+ resBodyStringData() {
458
+ return ConvertUtils.toString(this.resBodyData());
459
+ }
460
+
461
+ reqMethod() {
462
+ return this.req.method?.toUpperCase();
463
+ }
464
+
465
+ reqHeader(key: keyof typeof HttpHeaders | string) {
466
+ return this.req.headers[key.toLowerCase()];
467
+ }
468
+
469
+ get reqHost() {
470
+ return this.reqHeaderFirst(HttpHeaders.Host)
471
+ }
472
+
473
+ get reqHeaderObj(): ReqHeader {
474
+ const h = new ReqHeader();
475
+ Object.entries(this.req.headers).forEach(([k, v]) => {
476
+ h[k] = v;
477
+ });
478
+ return h;
479
+ }
480
+
481
+ reqHeaderFirst(key: HttpHeadersType | string, defaultValue?: string) {
482
+ const header = this.req.headers[key.toLowerCase()];
483
+ if (header && Array.isArray(header)) {
484
+ return header[0] ?? defaultValue;
485
+ } else {
486
+ return (header as string) ?? defaultValue;
487
+ }
488
+ }
489
+
490
+ public reqAuthorizationHeader() {
491
+ return this.reqHeaderFirst(HttpHeaders.Authorization);
492
+ }
493
+
494
+ reqRefreshTokenHeader() {
495
+ return this.reqHeaderFirst(HttpHeaders.Authorization);
496
+ }
497
+
498
+ resStatusCode(code?: undefined): number;
499
+ // eslint-disable-next-line no-dupe-class-members
500
+ resStatusCode(code: number | HttpStatus): RequestResponseChain<number>;
501
+ // eslint-disable-next-line no-dupe-class-members
502
+ resStatusCode(code: number | undefined | HttpStatus): number | RequestResponseChain<number> {
503
+ if (code) {
504
+ this.res.statusCode = code;
505
+ return new RequestResponseChain<number>(this.req, this.res, this.config, this.res.statusCode);
506
+ } else {
507
+ return this.res.statusCode;
508
+ }
509
+ }
510
+
511
+ resHeader(key: HttpHeadersType | string) {
512
+ return this.res.getHeader(key.toLowerCase());
513
+ }
514
+
515
+ resHeaderFirst(key: HttpHeadersType | string, defaultValue?: string) {
516
+ const header = this.res.getHeader(key.toLowerCase());
517
+ if (header && Array.isArray(header)) {
518
+ return header[0] ?? defaultValue;
519
+ } else {
520
+ return (header as string) ?? defaultValue;
521
+ }
522
+ }
523
+
524
+ async reqSession(): Promise<{ [key: string]: any }> {
525
+ if (this.config.sessionManager) {
526
+ return (await this.config.sessionManager.session(this)).dataSet.data;
527
+ } else {
528
+ return Promise.reject(new Error('Not SessionManager'));
529
+ }
530
+ }
531
+
532
+ reqSessionSet(key: string, value: any): void {
533
+ (this.reqSession as any)[key] = value;
534
+ }
535
+
536
+ reqSessionGet<T = any>(key: string): T | undefined {
537
+ const session = this.reqSession as any;
538
+ if (session) {
539
+ return session[key] as T;
540
+ }
541
+ }
542
+
543
+ resSetStatusCode(statusCode: number) {
544
+ this.res.statusCode = statusCode;
545
+ return this.createRequestResponseChain(this.res.statusCode);
546
+ }
547
+
548
+ // resEnd() {
549
+ // this.res.end();
550
+ // }
551
+
552
+ // eslint-disable-next-line no-undef
553
+ resWrite(chunk: string | Buffer | any, encoding: BufferEncoding = 'utf8') {
554
+ this.resWriteChunk = chunk;
555
+ return this.createRequestResponseChain(this.resWriteChunk);
556
+ }
557
+
558
+ // eslint-disable-next-line no-undef
559
+ resWriteJson(chunk: any, encoding: BufferEncoding = 'utf8') {
560
+ return this.resWrite(JSON.stringify(chunk), encoding);
561
+ }
562
+
563
+ resSetHeader(key: HttpHeadersType | string, value: string | string[]) {
564
+ return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), value));
565
+ }
566
+
567
+ resAddHeader(key: HttpHeadersType | string, value: string | string[]) {
568
+ const existingValue = this.res.getHeader(key.toLowerCase());
569
+ const newValue = Array.isArray(existingValue)
570
+ ? existingValue.concat(value)
571
+ : existingValue
572
+ ? [existingValue.toString(), ...[].concat(value)]
573
+ : value;
574
+ return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), newValue));
575
+ }
576
+
577
+ resSetHeaders(headers: { [key: string]: string | string[] }) {
578
+ Object.entries(headers).forEach(([key, value]) => this.resSetHeader(key, value));
579
+ return this.createRequestResponseChain();
580
+ }
581
+
582
+ resAddHeaders(headers: { [key: string]: string | string[] }) {
583
+ Object.entries(headers).forEach(([key, value]) => this.resAddHeader(key, value));
584
+ return this.createRequestResponseChain();
585
+ }
586
+
587
+ // 마지막 종료될때 타는거.
588
+ private async resEndChunk() {
589
+ const encoding = this.reqHeaderFirst(HttpHeaders.AcceptEncoding);
590
+ let data = this.resWriteChunk;
591
+ if (encoding?.includes('gzip')) {
592
+ data = await gzip(data);
593
+ this.resSetHeader(HttpHeaders.ContentEncoding, 'gzip');
594
+ }
595
+ this.res.end(data);
596
+ }
597
+
598
+ async resEnd(chunk?: string | Buffer) {
599
+ this.resWriteChunk = chunk ?? this.resWriteChunk;
600
+ if (this.req.readable) {
601
+ await this.reqBodyData();
602
+ await this.resEndChunk();
603
+ } else {
604
+ await this.resEndChunk();
605
+ }
606
+ }
607
+
608
+ // writeContinue(callback?: () => void) {
609
+ // this.res.writeContinue(callback);
610
+ // return new RequestResponseChain(this.req, this.res);
611
+ // }
612
+
613
+ // reqWrite(chunk?: any) {
614
+ // this.resWriteChunk = chunk;
615
+ // // this.res.write(chunk);
616
+ // return this.createRequestResponseChain();
617
+ // }
618
+
619
+ resWriteHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[] | { [key: string]: string | string[] }) {
620
+ return this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
621
+ }
622
+ resWriteHeadEnd(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[] | { [key: string]: string | string[] }) {
623
+ this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
624
+ this.res.end();
625
+ }
626
+
627
+ resIsDone() {
628
+ return this.res.finished || this.res.writableEnded || this.res.headersSent;
629
+ // return new RequestResponseChain(this.req, this.res, this.res.finished || this.res.writableEnded);
630
+ }
631
+
632
+ createRequestResponseChain<T = any>(data?: T) {
633
+ const requestResponseChain = new RequestResponseChain(this.req, this.res, this.config, data);
634
+ requestResponseChain.resWriteChunk = this.resWriteChunk;
635
+ requestResponseChain.reqBodyChunk = this.reqBodyChunk;
636
+ return requestResponseChain;
637
+ }
638
+
639
+ // res.on("readable", () => {
640
+ // console.log('readable???')
641
+ // });
642
+ // res.on('complete', function (details) {
643
+ // var size = details.req.bytes;
644
+ // console.log('complete-->', size)
645
+ // });
646
+ // res.on('finish', function() {
647
+ // console.log('finish??');
648
+ // });
649
+ // res.on('end', () => {
650
+ // console.log('end--?')
651
+ // });
652
+ }
653
+
654
+ export class RequestResponseChain<T> extends RequestResponse {
655
+ constructor(req: IncomingMessage, res: ServerResponse, config: Config, public result?: T) {
656
+ super(req, res, config);
657
+ }
658
+ }
@@ -0,0 +1,4 @@
1
+ export class HeaderData<T> {
2
+ constructor(public header: { [p: string]: [string] }, public data: T) {
3
+ }
4
+ }
@@ -0,0 +1,27 @@
1
+ import {HeaderData} from './HeaderData';
2
+
3
+ export type MultipartData = {
4
+ isFile: true;
5
+ name: string;
6
+ filename: string;
7
+ contentType: string;
8
+ value: Buffer
9
+ } | {
10
+ isFile: false;
11
+ name: string;
12
+ value: string;
13
+ }
14
+ // export class MultipartData<T> extends HeaderData<T> {
15
+ // constructor(private _info:MultipartDataInfo, header: { [p: string]: [string] }, data: T) {
16
+ // super(header, data);
17
+ //
18
+ // }
19
+ //
20
+ // get info() {
21
+ // return this._info;
22
+ // }
23
+ //
24
+ // get isFile() {
25
+ // return !!this._info.filename;
26
+ // }
27
+ // }