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

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 (199) hide show
  1. package/dist/cjs/SimpleBootHttpServer.d.ts +2 -1
  2. package/dist/cjs/SimpleBootHttpServer.d.ts.map +1 -1
  3. package/dist/cjs/SimpleBootHttpServer.js +53 -673
  4. package/dist/cjs/SimpleBootHttpServer.js.map +4 -4
  5. package/dist/cjs/codes/HttpHeaders.js +0 -2
  6. package/dist/cjs/codes/HttpHeaders.js.map +1 -1
  7. package/dist/cjs/codes/HttpMethod.js +0 -2
  8. package/dist/cjs/codes/HttpMethod.js.map +1 -1
  9. package/dist/cjs/codes/HttpStatus.js +0 -2
  10. package/dist/cjs/codes/HttpStatus.js.map +1 -1
  11. package/dist/cjs/codes/Mimes.js +0 -2
  12. package/dist/cjs/codes/Mimes.js.map +1 -1
  13. package/dist/cjs/codes/index.js +9 -126
  14. package/dist/cjs/codes/index.js.map +4 -4
  15. package/dist/cjs/decorators/MethodMapping.d.ts +0 -1
  16. package/dist/cjs/decorators/MethodMapping.d.ts.map +1 -1
  17. package/dist/cjs/decorators/MethodMapping.js +51 -53
  18. package/dist/cjs/decorators/MethodMapping.js.map +2 -2
  19. package/dist/cjs/decorators/index.js +3 -248
  20. package/dist/cjs/decorators/index.js.map +4 -4
  21. package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js +7 -8
  22. package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
  23. package/dist/cjs/endpoints/EndPoint.js +0 -2
  24. package/dist/cjs/endpoints/EndPoint.js.map +1 -1
  25. package/dist/cjs/endpoints/HeaderEndPoint.js +2 -4
  26. package/dist/cjs/endpoints/HeaderEndPoint.js.map +1 -1
  27. package/dist/cjs/endpoints/index.js +7 -54
  28. package/dist/cjs/endpoints/index.js.map +3 -3
  29. package/dist/cjs/errors/BadRequestError.js +5 -16
  30. package/dist/cjs/errors/BadRequestError.js.map +3 -3
  31. package/dist/cjs/errors/ForbiddenError.js +5 -16
  32. package/dist/cjs/errors/ForbiddenError.js.map +3 -3
  33. package/dist/cjs/errors/HttpError.js +7 -5
  34. package/dist/cjs/errors/HttpError.js.map +1 -1
  35. package/dist/cjs/errors/InternalServerError.js +5 -16
  36. package/dist/cjs/errors/InternalServerError.js.map +3 -3
  37. package/dist/cjs/errors/NotFoundError.js +5 -16
  38. package/dist/cjs/errors/NotFoundError.js.map +3 -3
  39. package/dist/cjs/errors/UnauthorizedError.js +5 -16
  40. package/dist/cjs/errors/UnauthorizedError.js.map +3 -3
  41. package/dist/cjs/errors/index.js +13 -64
  42. package/dist/cjs/errors/index.js.map +3 -3
  43. package/dist/cjs/filters/CacheFilter.js +14 -17
  44. package/dist/cjs/filters/CacheFilter.js.map +2 -2
  45. package/dist/cjs/filters/Filter.js +0 -2
  46. package/dist/cjs/filters/Filter.js.map +1 -1
  47. package/dist/cjs/filters/HttpStatusFilter.js +2 -4
  48. package/dist/cjs/filters/HttpStatusFilter.js.map +1 -1
  49. package/dist/cjs/filters/OpenApi3Filter.js +8 -20
  50. package/dist/cjs/filters/OpenApi3Filter.js.map +3 -3
  51. package/dist/cjs/filters/ResourceFilter.js +7 -7
  52. package/dist/cjs/filters/ResourceFilter.js.map +1 -1
  53. package/dist/cjs/filters/ThrowFilter.js +2 -4
  54. package/dist/cjs/filters/ThrowFilter.js.map +1 -1
  55. package/dist/cjs/filters/index.js +13 -299
  56. package/dist/cjs/filters/index.js.map +4 -4
  57. package/dist/cjs/index.d.ts +2 -12
  58. package/dist/cjs/index.d.ts.map +1 -1
  59. package/dist/cjs/index.js +2 -1734
  60. package/dist/cjs/index.js.map +4 -4
  61. package/dist/cjs/inject/InjectSituationType.js +0 -2
  62. package/dist/cjs/inject/InjectSituationType.js.map +1 -1
  63. package/dist/cjs/inject/index.js +3 -16
  64. package/dist/cjs/inject/index.js.map +4 -4
  65. package/dist/cjs/lifecycle/OnInit.js +0 -2
  66. package/dist/cjs/lifecycle/OnInit.js.map +1 -1
  67. package/dist/cjs/lifecycle/index.js +6 -2
  68. package/dist/cjs/lifecycle/index.js.map +1 -1
  69. package/dist/cjs/models/RequestResponse.js +26 -33
  70. package/dist/cjs/models/RequestResponse.js.map +3 -3
  71. package/dist/cjs/models/datas/HeaderData.js +2 -4
  72. package/dist/cjs/models/datas/HeaderData.js.map +1 -1
  73. package/dist/cjs/models/datas/MultipartData.js +0 -2
  74. package/dist/cjs/models/datas/MultipartData.js.map +1 -1
  75. package/dist/cjs/models/datas/ReqHeader.js +65 -4
  76. package/dist/cjs/models/datas/ReqHeader.js.map +1 -1
  77. package/dist/cjs/models/datas/Resource.js +8 -480
  78. package/dist/cjs/models/datas/Resource.js.map +4 -4
  79. package/dist/cjs/models/datas/body/ReqFormUrlBody.js +2 -4
  80. package/dist/cjs/models/datas/body/ReqFormUrlBody.js.map +1 -1
  81. package/dist/cjs/models/datas/body/ReqJsonBody.js +2 -4
  82. package/dist/cjs/models/datas/body/ReqJsonBody.js.map +1 -1
  83. package/dist/cjs/models/datas/body/ReqMultipartFormBody.js +2 -4
  84. package/dist/cjs/models/datas/body/ReqMultipartFormBody.js.map +1 -1
  85. package/dist/cjs/models/index.js +19 -574
  86. package/dist/cjs/models/index.js.map +4 -4
  87. package/dist/cjs/models/method/patch/PatchJson.js +2 -4
  88. package/dist/cjs/models/method/patch/PatchJson.js.map +1 -1
  89. package/dist/cjs/option/HttpServerOption.js +16 -11
  90. package/dist/cjs/option/HttpServerOption.js.map +1 -1
  91. package/dist/cjs/option/index.js +3 -50
  92. package/dist/cjs/option/index.js.map +3 -3
  93. package/dist/cjs/resolvers/Resolver.js +0 -2
  94. package/dist/cjs/resolvers/Resolver.js.map +1 -1
  95. package/dist/cjs/resolvers/ResourceResolver.js +10 -538
  96. package/dist/cjs/resolvers/ResourceResolver.js.map +4 -4
  97. package/dist/cjs/resolvers/index.js +5 -552
  98. package/dist/cjs/resolvers/index.js.map +4 -4
  99. package/dist/cjs/session/SessionManager.js +6 -479
  100. package/dist/cjs/session/SessionManager.js.map +4 -4
  101. package/dist/cjs/session/index.js +3 -560
  102. package/dist/cjs/session/index.js.map +4 -4
  103. package/dist/esm/SimpleBootHttpServer.d.ts +2 -1
  104. package/dist/esm/SimpleBootHttpServer.d.ts.map +1 -1
  105. package/dist/esm/SimpleBootHttpServer.js +37 -656
  106. package/dist/esm/SimpleBootHttpServer.js.map +4 -4
  107. package/dist/esm/codes/HttpHeaders.js +0 -1
  108. package/dist/esm/codes/HttpHeaders.js.map +1 -1
  109. package/dist/esm/codes/HttpMethod.js +0 -1
  110. package/dist/esm/codes/HttpMethod.js.map +1 -1
  111. package/dist/esm/codes/HttpStatus.js +0 -1
  112. package/dist/esm/codes/HttpStatus.js.map +1 -1
  113. package/dist/esm/codes/Mimes.js +0 -1
  114. package/dist/esm/codes/Mimes.js.map +1 -1
  115. package/dist/esm/codes/index.js +4 -115
  116. package/dist/esm/codes/index.js.map +4 -4
  117. package/dist/esm/decorators/MethodMapping.d.ts +0 -1
  118. package/dist/esm/decorators/MethodMapping.d.ts.map +1 -1
  119. package/dist/esm/decorators/MethodMapping.js +51 -52
  120. package/dist/esm/decorators/MethodMapping.js.map +2 -2
  121. package/dist/esm/decorators/index.js +1 -210
  122. package/dist/esm/decorators/index.js.map +4 -4
  123. package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js +7 -7
  124. package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
  125. package/dist/esm/endpoints/HeaderEndPoint.js +2 -3
  126. package/dist/esm/endpoints/HeaderEndPoint.js.map +1 -1
  127. package/dist/esm/endpoints/index.js +3 -45
  128. package/dist/esm/endpoints/index.js.map +3 -3
  129. package/dist/esm/errors/BadRequestError.js +5 -13
  130. package/dist/esm/errors/BadRequestError.js.map +3 -3
  131. package/dist/esm/errors/ForbiddenError.js +5 -13
  132. package/dist/esm/errors/ForbiddenError.js.map +3 -3
  133. package/dist/esm/errors/HttpError.js +7 -4
  134. package/dist/esm/errors/HttpError.js.map +1 -1
  135. package/dist/esm/errors/InternalServerError.js +5 -13
  136. package/dist/esm/errors/InternalServerError.js.map +3 -3
  137. package/dist/esm/errors/NotFoundError.js +5 -13
  138. package/dist/esm/errors/NotFoundError.js.map +3 -3
  139. package/dist/esm/errors/UnauthorizedError.js +5 -13
  140. package/dist/esm/errors/UnauthorizedError.js.map +3 -3
  141. package/dist/esm/errors/index.js +6 -51
  142. package/dist/esm/errors/index.js.map +3 -3
  143. package/dist/esm/filters/CacheFilter.js +14 -16
  144. package/dist/esm/filters/CacheFilter.js.map +2 -2
  145. package/dist/esm/filters/HttpStatusFilter.js +2 -3
  146. package/dist/esm/filters/HttpStatusFilter.js.map +1 -1
  147. package/dist/esm/filters/OpenApi3Filter.js +7 -16
  148. package/dist/esm/filters/OpenApi3Filter.js.map +3 -3
  149. package/dist/esm/filters/ResourceFilter.js +7 -6
  150. package/dist/esm/filters/ResourceFilter.js.map +1 -1
  151. package/dist/esm/filters/ThrowFilter.js +2 -3
  152. package/dist/esm/filters/ThrowFilter.js.map +1 -1
  153. package/dist/esm/filters/index.js +6 -277
  154. package/dist/esm/filters/index.js.map +4 -4
  155. package/dist/esm/index.d.ts +2 -12
  156. package/dist/esm/index.d.ts.map +1 -1
  157. package/dist/esm/index.js +2 -1659
  158. package/dist/esm/index.js.map +4 -4
  159. package/dist/esm/inject/InjectSituationType.js +0 -1
  160. package/dist/esm/inject/InjectSituationType.js.map +1 -1
  161. package/dist/esm/inject/index.js +1 -8
  162. package/dist/esm/inject/index.js.map +4 -4
  163. package/dist/esm/lifecycle/index.js +1 -0
  164. package/dist/esm/lifecycle/index.js.map +3 -3
  165. package/dist/esm/models/RequestResponse.js +23 -29
  166. package/dist/esm/models/RequestResponse.js.map +3 -3
  167. package/dist/esm/models/datas/HeaderData.js +2 -3
  168. package/dist/esm/models/datas/HeaderData.js.map +1 -1
  169. package/dist/esm/models/datas/ReqHeader.js +65 -3
  170. package/dist/esm/models/datas/ReqHeader.js.map +1 -1
  171. package/dist/esm/models/datas/Resource.js +7 -478
  172. package/dist/esm/models/datas/Resource.js.map +4 -4
  173. package/dist/esm/models/datas/body/ReqFormUrlBody.js +2 -3
  174. package/dist/esm/models/datas/body/ReqFormUrlBody.js.map +1 -1
  175. package/dist/esm/models/datas/body/ReqJsonBody.js +2 -3
  176. package/dist/esm/models/datas/body/ReqJsonBody.js.map +1 -1
  177. package/dist/esm/models/datas/body/ReqMultipartFormBody.js +2 -3
  178. package/dist/esm/models/datas/body/ReqMultipartFormBody.js.map +1 -1
  179. package/dist/esm/models/index.js +9 -548
  180. package/dist/esm/models/index.js.map +4 -4
  181. package/dist/esm/models/method/patch/PatchJson.js +2 -3
  182. package/dist/esm/models/method/patch/PatchJson.js.map +1 -1
  183. package/dist/esm/option/HttpServerOption.js +16 -10
  184. package/dist/esm/option/HttpServerOption.js.map +1 -1
  185. package/dist/esm/option/index.js +1 -42
  186. package/dist/esm/option/index.js.map +3 -3
  187. package/dist/esm/resolvers/ResourceResolver.js +8 -526
  188. package/dist/esm/resolvers/ResourceResolver.js.map +4 -4
  189. package/dist/esm/resolvers/index.js +2 -537
  190. package/dist/esm/resolvers/index.js.map +4 -4
  191. package/dist/esm/session/SessionManager.js +5 -477
  192. package/dist/esm/session/SessionManager.js.map +3 -3
  193. package/dist/esm/session/index.js +1 -552
  194. package/dist/esm/session/index.js.map +3 -3
  195. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +3 -1659
  196. package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
  197. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +2 -1673
  198. package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
  199. package/package.json +15 -12
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/models/datas/body/ReqMultipartFormBody.ts"],
4
4
  "sourcesContent": ["import {MultipartData} from '../MultipartData';\n\nexport class ReqMultipartFormBody {\n constructor(public field: MultipartData[] = []) {\n }\n}"],
5
- "mappings": ";AAEO,IAAM,uBAAN,MAA2B;AAAA,EAC9B,YAAmB,QAAyB,CAAC,GAAG;AAA7B;AAAA,EACnB;AACJ;",
5
+ "mappings": "AAEO,MAAM,qBAAqB;AAAA,EAC9B,YAAmB,QAAyB,CAAC,GAAG;AAA7B;AAAA,EACnB;AACJ;",
6
6
  "names": []
7
7
  }
@@ -1,549 +1,10 @@
1
- // src/models/RequestResponse.ts
2
- import { Intent } from "@dooboostore/simple-boot/intent/Intent";
3
- import { URL as URL2, URLSearchParams } from "url";
4
- import { Buffer } from "buffer";
5
-
6
- // src/models/datas/body/ReqFormUrlBody.ts
7
- var ReqFormUrlBody = class {
8
- };
9
-
10
- // src/models/datas/body/ReqJsonBody.ts
11
- var ReqJsonBody = class {
12
- };
13
-
14
- // src/models/datas/ReqHeader.ts
15
- var ReqHeader = class {
16
- };
17
-
18
- // src/models/RequestResponse.ts
19
- import { gzip } from "node-gzip";
20
- import { FileUtils } from "@dooboostore/core-node/file/FileUtils";
21
- import { ConvertUtils as CoreConvertUtils } from "@dooboostore/core/convert/ConvertUtils";
22
- import { ConvertUtils } from "@dooboostore/core-node/convert/ConvertUtils";
23
- var RequestResponse = class _RequestResponse {
24
- // protected sessionManager?: SessionManager;
25
- // constructor(req: IncomingMessage, res: ServerResponse);
26
- // constructor(req: RequestResponse);
27
- // constructor(req: IncomingMessage, res: ServerResponse, sessionManager?: SessionManager);
28
- // constructor(req: IncomingMessage | RequestResponse, res?: ServerResponse, sessionManager?: SessionManager) {
29
- // // this.req = req;
30
- // // this.res = res;
31
- // if (req instanceof RequestResponse) {
32
- // this.req = req.req;
33
- // this.res = req.res;
34
- // this.sessionManager = req.sessionManager;
35
- // } else {
36
- // this.req = req;
37
- // this.res = res!;
38
- // this.sessionManager = sessionManager;
39
- // }
40
- // }
41
- constructor(req, res, config) {
42
- if (req instanceof _RequestResponse) {
43
- this.req = req.req;
44
- this.res = req.res;
45
- this.config = config;
46
- } else {
47
- this.req = req;
48
- this.res = res;
49
- this.config = config;
50
- }
51
- }
52
- get reqSocket() {
53
- return this.req.socket;
54
- }
55
- get reqCookieMap() {
56
- let cookies = this.reqHeader("Cookie" /* Cookie */) ?? "";
57
- if (Array.isArray(cookies)) {
58
- cookies = cookies.join(";");
59
- }
60
- const map = /* @__PURE__ */ new Map();
61
- cookies.split(";").map((it) => it.trim().split("=")).forEach((it) => {
62
- map.set(it[0], it[1]);
63
- });
64
- return map;
65
- }
66
- reqCookieGet(key) {
67
- return this.reqCookieMap.get(key);
68
- }
69
- get reqRemoteAddress() {
70
- const ipHeader = this.req.headers["x-forwarded-for"];
71
- let ip = this.req.socket.remoteAddress;
72
- if (Array.isArray(ipHeader)) {
73
- ip = ipHeader.join(",").split(",").shift();
74
- } else if (typeof ipHeader === "string") {
75
- ip = ipHeader.split(",").shift();
76
- }
77
- return ip;
78
- }
79
- get reqUrlObject() {
80
- return new URL2(this.reqUrl, `${this.reqSocket ? "https://" : "http"}${this.reqHost ?? "localhost"}`);
81
- }
82
- get reqUrlPathName() {
83
- return this.reqUrlObj().pathname ?? "";
84
- }
85
- get reqUrl() {
86
- return this.req.url ?? "";
87
- }
88
- reqUrlObj(config) {
89
- return new URL2(`${config?.scheme ?? "http"}://${config?.host ? config?.host : this.reqHeaderFirst("Host" /* Host */) ?? "localhost"}${this.req.url ?? ""}`);
90
- }
91
- get reqUrlSearchParamTuples() {
92
- return Array.from(this.reqUrlObj().searchParams);
93
- }
94
- get reqUrlSearchParams() {
95
- return this.reqUrlObj().searchParams;
96
- }
97
- get reqUrlSearchParamsObj() {
98
- const entries = this.reqUrlObj().searchParams;
99
- return CoreConvertUtils.toObject(entries);
100
- }
101
- get reqPathSearchParamUrl() {
102
- const reqUrlObj = this.reqUrlObj();
103
- return reqUrlObj.pathname + (reqUrlObj.searchParams.toString() ? "?" + reqUrlObj.searchParams.toString() : "");
104
- }
105
- get reqReadable() {
106
- return this.req.readable;
107
- }
108
- get reqIntent() {
109
- return new Intent(this.reqPathSearchParamUrl);
110
- }
111
- reqHasContentTypeHeader(mime2) {
112
- return (this.reqHeaderFirst("Content-Type" /* ContentType */) ?? "").toLowerCase().indexOf(mime2.toLocaleLowerCase()) > -1;
113
- }
114
- reqHasAcceptHeader(mime2) {
115
- return (this.reqHeaderFirst("Accept" /* Accept */) ?? "").toLowerCase().indexOf(mime2.toLocaleLowerCase()) > -1;
116
- }
117
- reqBodyData() {
118
- return new Promise((resolve, reject) => {
119
- if (this.reqReadable) {
120
- const data = [];
121
- this.req.on("data", (chunk) => data.push(chunk));
122
- this.req.on("error", (err) => reject(err));
123
- this.req.on("end", () => {
124
- this.reqBodyChunk = Buffer.concat(data);
125
- resolve(this.reqBodyChunk);
126
- });
127
- } else {
128
- resolve(this.reqBodyChunk ?? Buffer.alloc(0));
129
- }
130
- });
131
- }
132
- resBodyData() {
133
- return this.resWriteChunk;
134
- }
135
- async reqBodyMultipartFormDataObject() {
136
- const m = await this.reqBodyMultipartFormData();
137
- const formData = {};
138
- for (const it of m) {
139
- if (it.isFile) {
140
- formData[it.name] = await FileUtils.writeFile(it.value, { originalName: it.filename });
141
- } else {
142
- const target = formData[it.name];
143
- if (Array.isArray(target)) {
144
- target.push(it.value);
145
- } else if (typeof target === "string") {
146
- formData[it.name] = [target, it.value];
147
- } else {
148
- formData[it.name] = it.value;
149
- }
150
- }
151
- }
152
- ;
153
- return formData;
154
- }
155
- reqBodyMultipartFormData() {
156
- return new Promise((resolve, reject) => {
157
- const contentTypeHeader = this.req.headers["content-type"];
158
- if (!contentTypeHeader || !contentTypeHeader.startsWith("multipart/form-data")) {
159
- return reject(new Error("Invalid Content-Type. Expected multipart/form-data."));
160
- }
161
- const boundaryMatch = contentTypeHeader.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
162
- if (!boundaryMatch) {
163
- return reject(new Error("Boundary not found in Content-Type header."));
164
- }
165
- const boundary = boundaryMatch[1] || boundaryMatch[2];
166
- if (!boundary) {
167
- return reject(new Error("Failed to extract boundary."));
168
- }
169
- const boundaryBuffer = Buffer.from(`--${boundary}`);
170
- const crlfBuffer = Buffer.from("\r\n");
171
- const doubleCrlfBuffer = Buffer.from("\r\n\r\n");
172
- const chunks = [];
173
- let totalLength = 0;
174
- this.req.on("data", (chunk) => {
175
- chunks.push(chunk);
176
- totalLength += chunk.length;
177
- });
178
- this.req.on("error", (err) => {
179
- reject(err);
180
- });
181
- this.req.on("end", () => {
182
- if (totalLength === 0) {
183
- return resolve([]);
184
- }
185
- const fullBuffer = Buffer.concat(chunks, totalLength);
186
- const parsedParts = [];
187
- let currentPosition = 0;
188
- let boundaryStartIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
189
- if (boundaryStartIndex === -1) {
190
- return reject(new Error("Initial boundary not found."));
191
- }
192
- currentPosition = boundaryStartIndex + boundaryBuffer.length;
193
- if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
194
- currentPosition += crlfBuffer.length;
195
- }
196
- while (currentPosition < fullBuffer.length) {
197
- const nextBoundaryIndex = fullBuffer.indexOf(boundaryBuffer, currentPosition);
198
- if (nextBoundaryIndex === -1) {
199
- break;
200
- }
201
- let partEndIndex = nextBoundaryIndex;
202
- if (partEndIndex > crlfBuffer.length && fullBuffer.slice(partEndIndex - crlfBuffer.length, partEndIndex).equals(crlfBuffer)) {
203
- partEndIndex -= crlfBuffer.length;
204
- }
205
- const partBuffer = fullBuffer.slice(currentPosition, partEndIndex);
206
- const headerBodySeparatorIndex = partBuffer.indexOf(doubleCrlfBuffer);
207
- if (headerBodySeparatorIndex === -1) {
208
- console.warn("Skipping malformed part: no header/body separator found.");
209
- currentPosition = nextBoundaryIndex + boundaryBuffer.length;
210
- if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
211
- currentPosition += crlfBuffer.length;
212
- }
213
- if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") break;
214
- continue;
215
- }
216
- const headerBuffer = partBuffer.slice(0, headerBodySeparatorIndex);
217
- const bodyBuffer = partBuffer.slice(headerBodySeparatorIndex + doubleCrlfBuffer.length);
218
- const headersStr = headerBuffer.toString("utf-8");
219
- const headers = {};
220
- headersStr.split("\r\n").forEach((line) => {
221
- const colonIndex = line.indexOf(":");
222
- if (colonIndex > 0) {
223
- const key = line.substring(0, colonIndex).trim().toLowerCase();
224
- const value = line.substring(colonIndex + 1).trim();
225
- headers[key] = value;
226
- }
227
- });
228
- const contentDisposition = headers["content-disposition"];
229
- if (!contentDisposition) {
230
- console.warn("Skipping part: no Content-Disposition header.");
231
- currentPosition = nextBoundaryIndex + boundaryBuffer.length;
232
- if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
233
- currentPosition += crlfBuffer.length;
234
- }
235
- if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") break;
236
- continue;
237
- }
238
- const nameMatch = contentDisposition.match(/name="([^"]+)"/i);
239
- const filenameMatch = contentDisposition.match(/filename="([^"]+)"/i);
240
- const name = nameMatch ? nameMatch[1] : null;
241
- const filename = filenameMatch ? filenameMatch[1] : null;
242
- const contentType = headers["content-type"] || null;
243
- if (name) {
244
- const isFile = !!filename;
245
- const multipartData = {
246
- name,
247
- isFile,
248
- // filename이 있으면 파일로 간주
249
- filename,
250
- contentType,
251
- value: isFile ? bodyBuffer : bodyBuffer.toString("utf-8")
252
- };
253
- parsedParts.push(multipartData);
254
- } else {
255
- console.warn("Skipping part: 'name' not found in Content-Disposition.");
256
- }
257
- currentPosition = nextBoundaryIndex + boundaryBuffer.length;
258
- if (fullBuffer.slice(currentPosition, currentPosition + crlfBuffer.length).equals(crlfBuffer)) {
259
- currentPosition += crlfBuffer.length;
260
- }
261
- if (fullBuffer.slice(currentPosition, currentPosition + 2).toString() === "--") {
262
- break;
263
- }
264
- }
265
- resolve(parsedParts);
266
- });
267
- });
268
- }
269
- async reqBodyStringData() {
270
- const data = (await this.reqBodyData()).toString();
271
- return data;
272
- }
273
- async reqBodyJsonData() {
274
- return JSON.parse(await this.reqBodyStringData());
275
- }
276
- async reqBodyFormUrlData() {
277
- const data = await this.reqBodyStringData();
278
- const formData = {};
279
- Array.from(new URLSearchParams(data).entries()).forEach(([k, v]) => {
280
- const target = formData[k];
281
- if (Array.isArray(target)) {
282
- target.push(v);
283
- } else if (typeof target === "string") {
284
- formData[k] = [target, v];
285
- } else {
286
- formData[k] = v;
287
- }
288
- });
289
- return formData;
290
- }
291
- async reqBodyReqFormUrlBody() {
292
- const data = await this.reqBodyFormUrlData();
293
- return Object.assign(new ReqFormUrlBody(), data);
294
- }
295
- async reqBodyReqJsonBody() {
296
- const data = await this.reqBodyStringData();
297
- return Object.assign(new ReqJsonBody(), data ? JSON.parse(data) : {});
298
- }
299
- // reqBodyReqMultipartFormBody(): Promise<ReqMultipartFormBody> {
300
- // return this.reqBodyMultipartFormData().then(it => new ReqMultipartFormBody(it))
301
- // }
302
- resBodyJsonData() {
303
- const data = ConvertUtils.toString(this.resBodyData());
304
- return data ? JSON.parse(data) : null;
305
- }
306
- resBodyStringData() {
307
- return ConvertUtils.toString(this.resBodyData());
308
- }
309
- reqMethod() {
310
- return this.req.method?.toUpperCase();
311
- }
312
- reqHeader(key) {
313
- return this.req.headers[key.toLowerCase()];
314
- }
315
- get reqHost() {
316
- return this.reqHeaderFirst("Host" /* Host */);
317
- }
318
- get reqHeaderObj() {
319
- const h = new ReqHeader();
320
- Object.entries(this.req.headers).forEach(([k, v]) => {
321
- h[k] = v;
322
- });
323
- return h;
324
- }
325
- reqHeaderFirst(key, defaultValue) {
326
- const header = this.req.headers[key.toLowerCase()];
327
- if (header && Array.isArray(header)) {
328
- return header[0] ?? defaultValue;
329
- } else {
330
- return header ?? defaultValue;
331
- }
332
- }
333
- reqAuthorizationHeader() {
334
- return this.reqHeaderFirst("Authorization" /* Authorization */);
335
- }
336
- reqRefreshTokenHeader() {
337
- return this.reqHeaderFirst("Authorization" /* Authorization */);
338
- }
339
- // eslint-disable-next-line no-dupe-class-members
340
- resStatusCode(code) {
341
- if (code) {
342
- this.res.statusCode = code;
343
- return new RequestResponseChain(this.req, this.res, this.config, this.res.statusCode);
344
- } else {
345
- return this.res.statusCode;
346
- }
347
- }
348
- resHeader(key) {
349
- return this.res.getHeader(key.toLowerCase());
350
- }
351
- resHeaderFirst(key, defaultValue) {
352
- const header = this.res.getHeader(key.toLowerCase());
353
- if (header && Array.isArray(header)) {
354
- return header[0] ?? defaultValue;
355
- } else {
356
- return header ?? defaultValue;
357
- }
358
- }
359
- async reqSession() {
360
- if (this.config.sessionManager) {
361
- return (await this.config.sessionManager.session(this)).dataSet.data;
362
- } else {
363
- return Promise.reject(new Error("Not SessionManager"));
364
- }
365
- }
366
- reqSessionSet(key, value) {
367
- this.reqSession[key] = value;
368
- }
369
- reqSessionGet(key) {
370
- const session = this.reqSession;
371
- if (session) {
372
- return session[key];
373
- }
374
- }
375
- resSetStatusCode(statusCode) {
376
- this.res.statusCode = statusCode;
377
- return this.createRequestResponseChain(this.res.statusCode);
378
- }
379
- // resEnd() {
380
- // this.res.end();
381
- // }
382
- // eslint-disable-next-line no-undef
383
- resWrite(chunk, encoding = "utf8") {
384
- this.resWriteChunk = chunk;
385
- return this.createRequestResponseChain(this.resWriteChunk);
386
- }
387
- // eslint-disable-next-line no-undef
388
- resWriteJson(chunk, encoding = "utf8") {
389
- return this.resWrite(JSON.stringify(chunk), encoding);
390
- }
391
- resSetHeader(key, value) {
392
- return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), value));
393
- }
394
- resAddHeader(key, value) {
395
- const existingValue = this.res.getHeader(key.toLowerCase());
396
- const newValue = Array.isArray(existingValue) ? existingValue.concat(value) : existingValue ? [existingValue.toString(), ...[].concat(value)] : value;
397
- return this.createRequestResponseChain(this.res.setHeader(key.toLowerCase(), newValue));
398
- }
399
- resSetHeaders(headers) {
400
- Object.entries(headers).forEach(([key, value]) => this.resSetHeader(key, value));
401
- return this.createRequestResponseChain();
402
- }
403
- resAddHeaders(headers) {
404
- Object.entries(headers).forEach(([key, value]) => this.resAddHeader(key, value));
405
- return this.createRequestResponseChain();
406
- }
407
- // 마지막 종료될때 타는거.
408
- async resEndChunk() {
409
- const encoding = this.reqHeaderFirst("Accept-Encoding" /* AcceptEncoding */);
410
- let data = this.resWriteChunk;
411
- if (encoding?.includes("gzip")) {
412
- data = await gzip(data);
413
- this.resSetHeader("Content-Encoding" /* ContentEncoding */, "gzip");
414
- }
415
- this.res.end(data);
416
- }
417
- async resEnd(chunk) {
418
- this.resWriteChunk = chunk ?? this.resWriteChunk;
419
- if (this.req.readable) {
420
- await this.reqBodyData();
421
- await this.resEndChunk();
422
- } else {
423
- await this.resEndChunk();
424
- }
425
- }
426
- // writeContinue(callback?: () => void) {
427
- // this.res.writeContinue(callback);
428
- // return new RequestResponseChain(this.req, this.res);
429
- // }
430
- // reqWrite(chunk?: any) {
431
- // this.resWriteChunk = chunk;
432
- // // this.res.write(chunk);
433
- // return this.createRequestResponseChain();
434
- // }
435
- resWriteHead(statusCode, headers) {
436
- return this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
437
- }
438
- resWriteHeadEnd(statusCode, headers) {
439
- this.createRequestResponseChain(this.res.writeHead(statusCode, headers));
440
- this.res.end();
441
- }
442
- resIsDone() {
443
- return this.res.finished || this.res.writableEnded || this.res.headersSent;
444
- }
445
- createRequestResponseChain(data) {
446
- const requestResponseChain = new RequestResponseChain(this.req, this.res, this.config, data);
447
- requestResponseChain.resWriteChunk = this.resWriteChunk;
448
- requestResponseChain.reqBodyChunk = this.reqBodyChunk;
449
- return requestResponseChain;
450
- }
451
- // res.on("readable", () => {
452
- // console.log('readable???')
453
- // });
454
- // res.on('complete', function (details) {
455
- // var size = details.req.bytes;
456
- // console.log('complete-->', size)
457
- // });
458
- // res.on('finish', function() {
459
- // console.log('finish??');
460
- // });
461
- // res.on('end', () => {
462
- // console.log('end--?')
463
- // });
464
- };
465
- var RequestResponseChain = class extends RequestResponse {
466
- constructor(req, res, config, result) {
467
- super(req, res, config);
468
- this.result = result;
469
- }
470
- };
471
-
472
- // src/models/datas/HeaderData.ts
473
- var HeaderData = class {
474
- constructor(header, data) {
475
- this.header = header;
476
- this.data = data;
477
- }
478
- };
479
-
480
- // src/models/datas/Resource.ts
481
- import fs from "fs";
482
- import path from "path";
483
- import mime from "mime-types";
484
- var Resource = class {
485
- constructor(path2, rootPath = process.cwd()) {
486
- this.path = path2;
487
- this.rootPath = rootPath;
488
- }
489
- get absolutePath() {
490
- if (this.path instanceof RequestResponse) {
491
- return path.join(this.rootPath, this.path.reqUrlObj().pathname);
492
- } else if (this.path instanceof URL) {
493
- return path.join(this.rootPath, this.path.pathname);
494
- } else {
495
- return path.join(this.rootPath, this.path);
496
- }
497
- }
498
- get conTentType() {
499
- return mime.lookup(this.absolutePath).toString();
500
- }
501
- get data() {
502
- const promise = new Promise((resolve, reject) => {
503
- fs.readFile("", (error, fileBuffer) => {
504
- if (error) {
505
- reject(error);
506
- }
507
- const fileContent = fileBuffer.toString();
508
- resolve(fileContent);
509
- });
510
- });
511
- return promise;
512
- }
513
- async write(rr) {
514
- rr.resStatusCode(200 /* Ok */);
515
- rr.resSetHeader("Content-Type" /* ContentType */, this.conTentType);
516
- await rr.resEnd(fs.readFileSync(this.absolutePath));
517
- }
518
- };
519
-
520
- // src/models/datas/body/ReqMultipartFormBody.ts
521
- var ReqMultipartFormBody = class {
522
- constructor(field = []) {
523
- this.field = field;
524
- }
525
- };
526
-
527
- // src/models/method/patch/PatchJson.ts
528
- import jsonpatch from "fast-json-patch";
529
- var PatchJson = class {
530
- constructor(patch) {
531
- this.patch = patch;
532
- }
533
- apply(obj) {
534
- obj = jsonpatch.applyPatch(obj, this.patch).newDocument;
535
- return obj;
536
- }
537
- };
538
- export {
539
- HeaderData,
540
- PatchJson,
541
- ReqFormUrlBody,
542
- ReqHeader,
543
- ReqJsonBody,
544
- ReqMultipartFormBody,
545
- RequestResponse,
546
- RequestResponseChain,
547
- Resource
548
- };
1
+ export * from "./RequestResponse.js";
2
+ export * from "./datas/HeaderData.js";
3
+ export * from "./datas/MultipartData.js";
4
+ export * from "./datas/ReqHeader.js";
5
+ export * from "./datas/Resource.js";
6
+ export * from "./datas/body/ReqFormUrlBody.js";
7
+ export * from "./datas/body/ReqJsonBody.js";
8
+ export * from "./datas/body/ReqMultipartFormBody.js";
9
+ export * from "./method/patch/PatchJson.js";
549
10
  //# sourceMappingURL=index.js.map