@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.
- package/dist/cjs/SimpleBootHttpServer.d.ts +2 -1
- package/dist/cjs/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/cjs/SimpleBootHttpServer.js +53 -673
- package/dist/cjs/SimpleBootHttpServer.js.map +4 -4
- package/dist/cjs/codes/HttpHeaders.js +0 -2
- package/dist/cjs/codes/HttpHeaders.js.map +1 -1
- package/dist/cjs/codes/HttpMethod.js +0 -2
- package/dist/cjs/codes/HttpMethod.js.map +1 -1
- package/dist/cjs/codes/HttpStatus.js +0 -2
- package/dist/cjs/codes/HttpStatus.js.map +1 -1
- package/dist/cjs/codes/Mimes.js +0 -2
- package/dist/cjs/codes/Mimes.js.map +1 -1
- package/dist/cjs/codes/index.js +9 -126
- package/dist/cjs/codes/index.js.map +4 -4
- package/dist/cjs/decorators/MethodMapping.d.ts +0 -1
- package/dist/cjs/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/cjs/decorators/MethodMapping.js +51 -53
- package/dist/cjs/decorators/MethodMapping.js.map +2 -2
- package/dist/cjs/decorators/index.js +3 -248
- package/dist/cjs/decorators/index.js.map +4 -4
- package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js +7 -8
- package/dist/cjs/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
- package/dist/cjs/endpoints/EndPoint.js +0 -2
- package/dist/cjs/endpoints/EndPoint.js.map +1 -1
- package/dist/cjs/endpoints/HeaderEndPoint.js +2 -4
- package/dist/cjs/endpoints/HeaderEndPoint.js.map +1 -1
- package/dist/cjs/endpoints/index.js +7 -54
- package/dist/cjs/endpoints/index.js.map +3 -3
- package/dist/cjs/errors/BadRequestError.js +5 -16
- package/dist/cjs/errors/BadRequestError.js.map +3 -3
- package/dist/cjs/errors/ForbiddenError.js +5 -16
- package/dist/cjs/errors/ForbiddenError.js.map +3 -3
- package/dist/cjs/errors/HttpError.js +7 -5
- package/dist/cjs/errors/HttpError.js.map +1 -1
- package/dist/cjs/errors/InternalServerError.js +5 -16
- package/dist/cjs/errors/InternalServerError.js.map +3 -3
- package/dist/cjs/errors/NotFoundError.js +5 -16
- package/dist/cjs/errors/NotFoundError.js.map +3 -3
- package/dist/cjs/errors/UnauthorizedError.js +5 -16
- package/dist/cjs/errors/UnauthorizedError.js.map +3 -3
- package/dist/cjs/errors/index.js +13 -64
- package/dist/cjs/errors/index.js.map +3 -3
- package/dist/cjs/filters/CacheFilter.js +14 -17
- package/dist/cjs/filters/CacheFilter.js.map +2 -2
- package/dist/cjs/filters/Filter.js +0 -2
- package/dist/cjs/filters/Filter.js.map +1 -1
- package/dist/cjs/filters/HttpStatusFilter.js +2 -4
- package/dist/cjs/filters/HttpStatusFilter.js.map +1 -1
- package/dist/cjs/filters/OpenApi3Filter.js +8 -20
- package/dist/cjs/filters/OpenApi3Filter.js.map +3 -3
- package/dist/cjs/filters/ResourceFilter.js +7 -7
- package/dist/cjs/filters/ResourceFilter.js.map +1 -1
- package/dist/cjs/filters/ThrowFilter.js +2 -4
- package/dist/cjs/filters/ThrowFilter.js.map +1 -1
- package/dist/cjs/filters/index.js +13 -299
- package/dist/cjs/filters/index.js.map +4 -4
- package/dist/cjs/index.d.ts +2 -12
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -1734
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/inject/InjectSituationType.js +0 -2
- package/dist/cjs/inject/InjectSituationType.js.map +1 -1
- package/dist/cjs/inject/index.js +3 -16
- package/dist/cjs/inject/index.js.map +4 -4
- package/dist/cjs/lifecycle/OnInit.js +0 -2
- package/dist/cjs/lifecycle/OnInit.js.map +1 -1
- package/dist/cjs/lifecycle/index.js +6 -2
- package/dist/cjs/lifecycle/index.js.map +1 -1
- package/dist/cjs/models/RequestResponse.js +26 -33
- package/dist/cjs/models/RequestResponse.js.map +3 -3
- package/dist/cjs/models/datas/HeaderData.js +2 -4
- package/dist/cjs/models/datas/HeaderData.js.map +1 -1
- package/dist/cjs/models/datas/MultipartData.js +0 -2
- package/dist/cjs/models/datas/MultipartData.js.map +1 -1
- package/dist/cjs/models/datas/ReqHeader.js +65 -4
- package/dist/cjs/models/datas/ReqHeader.js.map +1 -1
- package/dist/cjs/models/datas/Resource.js +8 -480
- package/dist/cjs/models/datas/Resource.js.map +4 -4
- package/dist/cjs/models/datas/body/ReqFormUrlBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqFormUrlBody.js.map +1 -1
- package/dist/cjs/models/datas/body/ReqJsonBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqJsonBody.js.map +1 -1
- package/dist/cjs/models/datas/body/ReqMultipartFormBody.js +2 -4
- package/dist/cjs/models/datas/body/ReqMultipartFormBody.js.map +1 -1
- package/dist/cjs/models/index.js +19 -574
- package/dist/cjs/models/index.js.map +4 -4
- package/dist/cjs/models/method/patch/PatchJson.js +2 -4
- package/dist/cjs/models/method/patch/PatchJson.js.map +1 -1
- package/dist/cjs/option/HttpServerOption.js +16 -11
- package/dist/cjs/option/HttpServerOption.js.map +1 -1
- package/dist/cjs/option/index.js +3 -50
- package/dist/cjs/option/index.js.map +3 -3
- package/dist/cjs/resolvers/Resolver.js +0 -2
- package/dist/cjs/resolvers/Resolver.js.map +1 -1
- package/dist/cjs/resolvers/ResourceResolver.js +10 -538
- package/dist/cjs/resolvers/ResourceResolver.js.map +4 -4
- package/dist/cjs/resolvers/index.js +5 -552
- package/dist/cjs/resolvers/index.js.map +4 -4
- package/dist/cjs/session/SessionManager.js +6 -479
- package/dist/cjs/session/SessionManager.js.map +4 -4
- package/dist/cjs/session/index.js +3 -560
- package/dist/cjs/session/index.js.map +4 -4
- package/dist/esm/SimpleBootHttpServer.d.ts +2 -1
- package/dist/esm/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/esm/SimpleBootHttpServer.js +37 -656
- package/dist/esm/SimpleBootHttpServer.js.map +4 -4
- package/dist/esm/codes/HttpHeaders.js +0 -1
- package/dist/esm/codes/HttpHeaders.js.map +1 -1
- package/dist/esm/codes/HttpMethod.js +0 -1
- package/dist/esm/codes/HttpMethod.js.map +1 -1
- package/dist/esm/codes/HttpStatus.js +0 -1
- package/dist/esm/codes/HttpStatus.js.map +1 -1
- package/dist/esm/codes/Mimes.js +0 -1
- package/dist/esm/codes/Mimes.js.map +1 -1
- package/dist/esm/codes/index.js +4 -115
- package/dist/esm/codes/index.js.map +4 -4
- package/dist/esm/decorators/MethodMapping.d.ts +0 -1
- package/dist/esm/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/esm/decorators/MethodMapping.js +51 -52
- package/dist/esm/decorators/MethodMapping.js.map +2 -2
- package/dist/esm/decorators/index.js +1 -210
- package/dist/esm/decorators/index.js.map +4 -4
- package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js +7 -7
- package/dist/esm/endpoints/CrossDomainHeaderEndPoint.js.map +1 -1
- package/dist/esm/endpoints/HeaderEndPoint.js +2 -3
- package/dist/esm/endpoints/HeaderEndPoint.js.map +1 -1
- package/dist/esm/endpoints/index.js +3 -45
- package/dist/esm/endpoints/index.js.map +3 -3
- package/dist/esm/errors/BadRequestError.js +5 -13
- package/dist/esm/errors/BadRequestError.js.map +3 -3
- package/dist/esm/errors/ForbiddenError.js +5 -13
- package/dist/esm/errors/ForbiddenError.js.map +3 -3
- package/dist/esm/errors/HttpError.js +7 -4
- package/dist/esm/errors/HttpError.js.map +1 -1
- package/dist/esm/errors/InternalServerError.js +5 -13
- package/dist/esm/errors/InternalServerError.js.map +3 -3
- package/dist/esm/errors/NotFoundError.js +5 -13
- package/dist/esm/errors/NotFoundError.js.map +3 -3
- package/dist/esm/errors/UnauthorizedError.js +5 -13
- package/dist/esm/errors/UnauthorizedError.js.map +3 -3
- package/dist/esm/errors/index.js +6 -51
- package/dist/esm/errors/index.js.map +3 -3
- package/dist/esm/filters/CacheFilter.js +14 -16
- package/dist/esm/filters/CacheFilter.js.map +2 -2
- package/dist/esm/filters/HttpStatusFilter.js +2 -3
- package/dist/esm/filters/HttpStatusFilter.js.map +1 -1
- package/dist/esm/filters/OpenApi3Filter.js +7 -16
- package/dist/esm/filters/OpenApi3Filter.js.map +3 -3
- package/dist/esm/filters/ResourceFilter.js +7 -6
- package/dist/esm/filters/ResourceFilter.js.map +1 -1
- package/dist/esm/filters/ThrowFilter.js +2 -3
- package/dist/esm/filters/ThrowFilter.js.map +1 -1
- package/dist/esm/filters/index.js +6 -277
- package/dist/esm/filters/index.js.map +4 -4
- package/dist/esm/index.d.ts +2 -12
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1659
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/inject/InjectSituationType.js +0 -1
- package/dist/esm/inject/InjectSituationType.js.map +1 -1
- package/dist/esm/inject/index.js +1 -8
- package/dist/esm/inject/index.js.map +4 -4
- package/dist/esm/lifecycle/index.js +1 -0
- package/dist/esm/lifecycle/index.js.map +3 -3
- package/dist/esm/models/RequestResponse.js +23 -29
- package/dist/esm/models/RequestResponse.js.map +3 -3
- package/dist/esm/models/datas/HeaderData.js +2 -3
- package/dist/esm/models/datas/HeaderData.js.map +1 -1
- package/dist/esm/models/datas/ReqHeader.js +65 -3
- package/dist/esm/models/datas/ReqHeader.js.map +1 -1
- package/dist/esm/models/datas/Resource.js +7 -478
- package/dist/esm/models/datas/Resource.js.map +4 -4
- package/dist/esm/models/datas/body/ReqFormUrlBody.js +2 -3
- package/dist/esm/models/datas/body/ReqFormUrlBody.js.map +1 -1
- package/dist/esm/models/datas/body/ReqJsonBody.js +2 -3
- package/dist/esm/models/datas/body/ReqJsonBody.js.map +1 -1
- package/dist/esm/models/datas/body/ReqMultipartFormBody.js +2 -3
- package/dist/esm/models/datas/body/ReqMultipartFormBody.js.map +1 -1
- package/dist/esm/models/index.js +9 -548
- package/dist/esm/models/index.js.map +4 -4
- package/dist/esm/models/method/patch/PatchJson.js +2 -3
- package/dist/esm/models/method/patch/PatchJson.js.map +1 -1
- package/dist/esm/option/HttpServerOption.js +16 -10
- package/dist/esm/option/HttpServerOption.js.map +1 -1
- package/dist/esm/option/index.js +1 -42
- package/dist/esm/option/index.js.map +3 -3
- package/dist/esm/resolvers/ResourceResolver.js +8 -526
- package/dist/esm/resolvers/ResourceResolver.js.map +4 -4
- package/dist/esm/resolvers/index.js +2 -537
- package/dist/esm/resolvers/index.js.map +4 -4
- package/dist/esm/session/SessionManager.js +5 -477
- package/dist/esm/session/SessionManager.js.map +3 -3
- package/dist/esm/session/index.js +1 -552
- package/dist/esm/session/index.js.map +3 -3
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +3 -1659
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +2 -1673
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
- 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": "
|
|
5
|
+
"mappings": "AAEO,MAAM,qBAAqB;AAAA,EAC9B,YAAmB,QAAyB,CAAC,GAAG;AAA7B;AAAA,EACnB;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/models/index.js
CHANGED
|
@@ -1,549 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|