@moostjs/event-http 0.3.9 → 0.3.11

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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { WooksHttp, createHttpApp, useRequest, HttpError, useHttpContext, useHeaders, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse, useSetCookies } from '@wooksjs/event-http';
1
+ import { WooksHttp, createHttpApp, HttpError, useRequest, useHttpContext, useHeaders, EHttpStatusCode, WooksURLSearchParams, useStatus, useSetHeader, useSetCookie, useAuthorization, useCookies, useSearchParams, useResponse, useSetCookies } from '@wooksjs/event-http';
2
2
  export { HttpError, useHttpContext } from '@wooksjs/event-http';
3
3
  import { defineMoostEventHandler, getMoostMate, Resolve, Intercept, TInterceptorPriority, defineInterceptorFn } from 'moost';
4
4
  import { createProvideRegistry } from '@prostojs/infact';
@@ -6,707 +6,653 @@ import { Server } from 'http';
6
6
  import { Server as Server$1 } from 'https';
7
7
  import { attachHook } from '@wooksjs/event-core';
8
8
 
9
- /******************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
- /* global Reflect, Promise */
24
-
25
-
26
- function __awaiter$1(thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- });
9
+ const LOGGER_TITLE = 'moost-http';
10
+ const CONTEXT_TYPE = 'HTTP';
11
+ /**
12
+ * ## Moost HTTP Adapter
13
+ *
14
+ * Moost Adapter for HTTP events
15
+ *
16
+ * ```ts
17
+ * │ // HTTP server example
18
+ * │ import { MoostHttp, Get } from '@moostjs/event-http'
19
+ * │ import { Moost, Param } from 'moost'
20
+ *
21
+ * │ class MyServer extends Moost {
22
+ * │ @Get('test/:name')
23
+ * │ test(@Param('name') name: string) {
24
+ * │ return { message: `Hello ${name}!` }
25
+ * │ }
26
+ * │ }
27
+ *
28
+ * │ const app = new MyServer()
29
+ * │ const http = new MoostHttp()
30
+ * │ app.adapter(http).listen(3000, () => {
31
+ * │ app.getLogger('MyApp').log('Up on port 3000')
32
+ * │ })
33
+ * │ app.init()
34
+ * ```
35
+ */
36
+ class MoostHttp {
37
+ constructor(httpApp) {
38
+ this.pathBuilders = {};
39
+ if (httpApp && httpApp instanceof WooksHttp) {
40
+ this.httpApp = httpApp;
41
+ }
42
+ else if (httpApp) {
43
+ this.httpApp = createHttpApp({
44
+ ...httpApp,
45
+ onNotFound: this.onNotFound.bind(this),
46
+ });
47
+ }
48
+ else {
49
+ this.httpApp = createHttpApp({
50
+ onNotFound: this.onNotFound.bind(this),
51
+ });
52
+ }
53
+ }
54
+ getHttpApp() {
55
+ return this.httpApp;
56
+ }
57
+ getServerCb() {
58
+ return this.httpApp.getServerCb();
59
+ }
60
+ listen(...args) {
61
+ return this.httpApp.listen(...args);
62
+ }
63
+ async onNotFound() {
64
+ const response = await defineMoostEventHandler({
65
+ loggerTitle: LOGGER_TITLE,
66
+ getIterceptorHandler: () => this.moost?.getGlobalInterceptorHandler(),
67
+ getControllerInstance: () => this.moost,
68
+ callControllerMethod: () => undefined,
69
+ })();
70
+ if (!response) {
71
+ throw new HttpError(404, 'Resource Not Found');
72
+ }
73
+ return response;
74
+ }
75
+ onInit(moost) {
76
+ this.moost = moost;
77
+ }
78
+ getProvideRegistry() {
79
+ return createProvideRegistry([WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()], [
80
+ Server,
81
+ () => this.getHttpApp().getServer(),
82
+ ], [
83
+ Server$1,
84
+ () => this.getHttpApp().getServer(),
85
+ ]);
86
+ }
87
+ getLogger() {
88
+ return this.getHttpApp().getLogger('moost-http');
89
+ }
90
+ bindHandler(opts) {
91
+ let fn;
92
+ for (const handler of opts.handlers) {
93
+ if (handler.type !== 'HTTP')
94
+ continue;
95
+ const httpPath = handler.path;
96
+ const path = typeof httpPath === 'string'
97
+ ? httpPath
98
+ : typeof opts.method === 'string'
99
+ ? opts.method
100
+ : '';
101
+ const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
102
+ if (!fn) {
103
+ fn = defineMoostEventHandler({
104
+ contextType: CONTEXT_TYPE,
105
+ loggerTitle: LOGGER_TITLE,
106
+ getIterceptorHandler: opts.getIterceptorHandler,
107
+ getControllerInstance: opts.getInstance,
108
+ controllerMethod: opts.method,
109
+ resolveArgs: opts.resolveArgs,
110
+ manualUnscope: true,
111
+ hooks: {
112
+ init: ({ unscope }) => {
113
+ const { rawRequest } = useRequest();
114
+ rawRequest.on('end', unscope); // will unscope on request end
115
+ },
116
+ },
117
+ });
118
+ }
119
+ const routerBinding = this.httpApp.on(handler.method, targetPath, fn);
120
+ const { getPath: pathBuilder } = routerBinding;
121
+ const methodMeta = getMoostMate().read(opts.fakeInstance, opts.method) ||
122
+ {};
123
+ const id = (methodMeta.id || opts.method);
124
+ if (id) {
125
+ const methods = (this.pathBuilders[id] =
126
+ this.pathBuilders[id] || {});
127
+ if (handler.method === '*') {
128
+ methods.GET = pathBuilder;
129
+ methods.PUT = pathBuilder;
130
+ methods.PATCH = pathBuilder;
131
+ methods.POST = pathBuilder;
132
+ methods.DELETE = pathBuilder;
133
+ }
134
+ else {
135
+ methods[handler.method] = pathBuilder;
136
+ }
137
+ }
138
+ opts.logHandler(`${''}(${handler.method})${''}${targetPath}`);
139
+ const args = routerBinding.getArgs();
140
+ const params = {};
141
+ args.forEach(a => params[a] = `{${a}}`);
142
+ opts.register(handler, routerBinding.getPath(params), args);
143
+ }
144
+ }
34
145
  }
35
146
 
36
- const LOGGER_TITLE = 'moost-http';
37
- const CONTEXT_TYPE = 'HTTP';
38
- /**
39
- * ## Moost HTTP Adapter
40
- *
41
- * Moost Adapter for HTTP events
42
- *
43
- * ```ts
44
- * │ // HTTP server example
45
- * │ import { MoostHttp, Get } from '@moostjs/event-http'
46
- * │ import { Moost, Param } from 'moost'
47
- * │
48
- * │ class MyServer extends Moost {
49
- * │ @Get('test/:name')
50
- * │ test(@Param('name') name: string) {
51
- * │ return { message: `Hello ${name}!` }
52
- * │ }
53
- * │ }
54
- * │
55
- * │ const app = new MyServer()
56
- * │ const http = new MoostHttp()
57
- * │ app.adapter(http).listen(3000, () => {
58
- * │ app.getLogger('MyApp').log('Up on port 3000')
59
- * │ })
60
- * │ app.init()
61
- * ```
62
- */
63
- class MoostHttp {
64
- constructor(httpApp) {
65
- this.pathBuilders = {};
66
- if (httpApp && httpApp instanceof WooksHttp) {
67
- this.httpApp = httpApp;
68
- }
69
- else if (httpApp) {
70
- this.httpApp = createHttpApp(Object.assign(Object.assign({}, httpApp), { onNotFound: this.onNotFound.bind(this) }));
71
- }
72
- else {
73
- this.httpApp = createHttpApp({
74
- onNotFound: this.onNotFound.bind(this),
75
- });
76
- }
77
- }
78
- getHttpApp() {
79
- return this.httpApp;
80
- }
81
- getServerCb() {
82
- return this.httpApp.getServerCb();
83
- }
84
- listen(...args) {
85
- return this.httpApp.listen(...args);
86
- }
87
- onNotFound() {
88
- return __awaiter$1(this, void 0, void 0, function* () {
89
- const response = yield defineMoostEventHandler({
90
- loggerTitle: LOGGER_TITLE,
91
- getIterceptorHandler: () => { var _a; return (_a = this.moost) === null || _a === void 0 ? void 0 : _a.getGlobalInterceptorHandler(); },
92
- getControllerInstance: () => this.moost,
93
- callControllerMethod: () => undefined,
94
- })();
95
- if (!response) {
96
- throw new HttpError(404, 'Resource Not Found');
97
- }
98
- return response;
99
- });
100
- }
101
- onInit(moost) {
102
- this.moost = moost;
103
- }
104
- getProvideRegistry() {
105
- return createProvideRegistry([WooksHttp, () => this.getHttpApp()], ['WooksHttp', () => this.getHttpApp()], [
106
- Server,
107
- () => this.getHttpApp().getServer(),
108
- ], [
109
- Server$1,
110
- () => this.getHttpApp().getServer(),
111
- ]);
112
- }
113
- getLogger() {
114
- return this.getHttpApp().getLogger('moost-http');
115
- }
116
- bindHandler(opts) {
117
- let fn;
118
- for (const handler of opts.handlers) {
119
- if (handler.type !== 'HTTP')
120
- continue;
121
- const httpPath = handler.path;
122
- const path = typeof httpPath === 'string'
123
- ? httpPath
124
- : typeof opts.method === 'string'
125
- ? opts.method
126
- : '';
127
- const targetPath = `${opts.prefix || ''}/${path}`.replace(/\/\/+/g, '/') + `${path.endsWith('//') ? '/' : ''}`; // explicit double slash "//" -> force url to end with slash
128
- if (!fn) {
129
- fn = defineMoostEventHandler({
130
- contextType: CONTEXT_TYPE,
131
- loggerTitle: LOGGER_TITLE,
132
- getIterceptorHandler: opts.getIterceptorHandler,
133
- getControllerInstance: opts.getInstance,
134
- controllerMethod: opts.method,
135
- resolveArgs: opts.resolveArgs,
136
- manualUnscope: true,
137
- hooks: {
138
- init: ({ unscope }) => {
139
- const { rawRequest } = useRequest();
140
- rawRequest.on('end', unscope); // will unscope on request end
141
- },
142
- },
143
- });
144
- }
145
- const routerBinding = this.httpApp.on(handler.method, targetPath, fn);
146
- const { getPath: pathBuilder } = routerBinding;
147
- const methodMeta = getMoostMate().read(opts.fakeInstance, opts.method) ||
148
- {};
149
- const id = (methodMeta.id || opts.method);
150
- if (id) {
151
- const methods = (this.pathBuilders[id] =
152
- this.pathBuilders[id] || {});
153
- if (handler.method === '*') {
154
- methods.GET = pathBuilder;
155
- methods.PUT = pathBuilder;
156
- methods.PATCH = pathBuilder;
157
- methods.POST = pathBuilder;
158
- methods.DELETE = pathBuilder;
159
- }
160
- else {
161
- methods[handler.method] = pathBuilder;
162
- }
163
- }
164
- opts.logHandler(`${''}(${handler.method})${''}${targetPath}`);
165
- const args = routerBinding.getArgs();
166
- const params = {};
167
- args.forEach(a => params[a] = `{${a}}`);
168
- opts.register(handler, routerBinding.getPath(params), args);
169
- }
170
- }
147
+ function HttpMethod(method, path) {
148
+ return getMoostMate().decorate('handlers', { method, path, type: 'HTTP' }, true);
171
149
  }
172
-
173
- function HttpMethod(method, path) {
174
- return getMoostMate().decorate('handlers', { method, path, type: 'HTTP' }, true);
175
- }
176
- const All = (path) => HttpMethod('*', path);
177
- const Get = (path) => HttpMethod('GET', path);
178
- const Post = (path) => HttpMethod('POST', path);
179
- const Put = (path) => HttpMethod('PUT', path);
180
- const Delete = (path) => HttpMethod('DELETE', path);
150
+ const All = (path) => HttpMethod('*', path);
151
+ const Get = (path) => HttpMethod('GET', path);
152
+ const Post = (path) => HttpMethod('POST', path);
153
+ const Put = (path) => HttpMethod('PUT', path);
154
+ const Delete = (path) => HttpMethod('DELETE', path);
181
155
  const Patch = (path) => HttpMethod('PATCH', path);
182
156
 
183
- /******************************************************************************
184
- Copyright (c) Microsoft Corporation.
185
-
186
- Permission to use, copy, modify, and/or distribute this software for any
187
- purpose with or without fee is hereby granted.
188
-
189
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
190
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
191
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
192
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
193
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
194
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
195
- PERFORMANCE OF THIS SOFTWARE.
196
- ***************************************************************************** */
197
-
198
- function __awaiter(thisArg, _arguments, P, generator) {
199
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
200
- return new (P || (P = Promise))(function (resolve, reject) {
201
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
202
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
203
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
204
- step((generator = generator.apply(thisArg, _arguments || [])).next());
205
- });
157
+ const compressors = {
158
+ identity: {
159
+ compress: (v) => v,
160
+ uncompress: (v) => v,
161
+ },
162
+ };
163
+ async function uncompressBody(encodings, body) {
164
+ let newBody = body;
165
+ for (const e of encodings.reverse()) {
166
+ if (!compressors[e]) {
167
+ throw new Error(`Usupported compression type "${e}".`);
168
+ }
169
+ newBody = await compressors[e].uncompress(body);
170
+ }
171
+ return newBody;
206
172
  }
207
173
 
208
- const compressors = {
209
- identity: {
210
- compress: (v) => v,
211
- uncompress: (v) => v,
212
- },
213
- };
214
- function uncompressBody(encodings, body) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- let newBody = body;
217
- for (const e of encodings.reverse()) {
218
- if (!compressors[e]) {
219
- throw new Error(`Usupported compression type "${e}".`);
220
- }
221
- newBody = yield compressors[e].uncompress(body);
222
- }
223
- return newBody;
224
- });
174
+ function useBody() {
175
+ const { store } = useHttpContext();
176
+ const { init } = store('request');
177
+ const { rawBody } = useRequest();
178
+ const { 'content-type': contentType, 'content-encoding': contentEncoding } = useHeaders();
179
+ function contentIs(type) {
180
+ return (contentType || '').indexOf(type) >= 0;
181
+ }
182
+ const isJson = () => init('isJson', () => contentIs('application/json'));
183
+ const isHtml = () => init('isHtml', () => contentIs('text/html'));
184
+ const isXml = () => init('isXml', () => contentIs('text/xml'));
185
+ const isText = () => init('isText', () => contentIs('text/plain'));
186
+ const isBinary = () => init('isBinary', () => contentIs('application/octet-stream'));
187
+ const isFormData = () => init('isFormData', () => contentIs('multipart/form-data'));
188
+ const isUrlencoded = () => init('isUrlencoded', () => contentIs('application/x-www-form-urlencoded'));
189
+ const isCompressed = () => init('isCompressed', () => {
190
+ const parts = contentEncodings();
191
+ for (const p of parts) {
192
+ if (['deflate', 'gzip', 'br'].includes(p))
193
+ return true;
194
+ }
195
+ return false;
196
+ });
197
+ const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '')
198
+ .split(',')
199
+ .map((p) => p.trim())
200
+ .filter((p) => !!p));
201
+ const parseBody = () => init('parsed', async () => {
202
+ const body = await uncompressBody(contentEncodings(), (await rawBody()).toString());
203
+ if (isJson())
204
+ return jsonParser(body);
205
+ else if (isFormData())
206
+ return formDataParser(body);
207
+ else if (isUrlencoded())
208
+ return urlEncodedParser(body);
209
+ else if (isBinary())
210
+ return textParser(body);
211
+ else
212
+ return textParser(body);
213
+ });
214
+ function jsonParser(v) {
215
+ try {
216
+ return JSON.parse(v);
217
+ }
218
+ catch (e) {
219
+ throw new HttpError(400, e.message);
220
+ }
221
+ }
222
+ function textParser(v) {
223
+ return v;
224
+ }
225
+ function formDataParser(v) {
226
+ const boundary = '--' +
227
+ (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
228
+ if (!boundary)
229
+ throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
230
+ const parts = v.trim().split(boundary);
231
+ const result = {};
232
+ let key = '';
233
+ let partContentType = 'text/plain';
234
+ for (const part of parts) {
235
+ parsePart();
236
+ key = '';
237
+ partContentType = 'text/plain';
238
+ let valueMode = false;
239
+ const lines = part
240
+ .trim()
241
+ .split(/\n/g)
242
+ .map((s) => s.trim());
243
+ for (const line of lines) {
244
+ if (valueMode) {
245
+ if (!result[key]) {
246
+ result[key] = line;
247
+ }
248
+ else {
249
+ result[key] += '\n' + line;
250
+ }
251
+ }
252
+ else {
253
+ if (!line || line === '--') {
254
+ valueMode = !!key;
255
+ if (valueMode) {
256
+ key = key.replace(/^["']/, '').replace(/["']$/, '');
257
+ }
258
+ continue;
259
+ }
260
+ if (line
261
+ .toLowerCase()
262
+ .startsWith('content-disposition: form-data;')) {
263
+ key = (/name=([^;]+)/.exec(line) || [])[1];
264
+ if (!key)
265
+ throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
266
+ continue;
267
+ }
268
+ if (line.toLowerCase().startsWith('content-type:')) {
269
+ partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
270
+ if (!partContentType)
271
+ throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
272
+ continue;
273
+ }
274
+ }
275
+ }
276
+ }
277
+ parsePart();
278
+ function parsePart() {
279
+ if (key) {
280
+ if (partContentType.indexOf('application/json') >= 0) {
281
+ result[key] = JSON.parse(result[key]);
282
+ }
283
+ }
284
+ }
285
+ return result;
286
+ }
287
+ function urlEncodedParser(v) {
288
+ return new WooksURLSearchParams(v.trim()).toJson();
289
+ }
290
+ return {
291
+ isJson,
292
+ isHtml,
293
+ isXml,
294
+ isText,
295
+ isBinary,
296
+ isFormData,
297
+ isUrlencoded,
298
+ isCompressed,
299
+ contentEncodings,
300
+ parseBody,
301
+ rawBody,
302
+ };
225
303
  }
226
304
 
227
- function useBody() {
228
- const { store } = useHttpContext();
229
- const { init } = store('request');
230
- const { rawBody } = useRequest();
231
- const { 'content-type': contentType, 'content-encoding': contentEncoding } = useHeaders();
232
- function contentIs(type) {
233
- return (contentType || '').indexOf(type) >= 0;
234
- }
235
- const isJson = () => init('isJson', () => contentIs('application/json'));
236
- const isHtml = () => init('isHtml', () => contentIs('text/html'));
237
- const isXml = () => init('isXml', () => contentIs('text/xml'));
238
- const isText = () => init('isText', () => contentIs('text/plain'));
239
- const isBinary = () => init('isBinary', () => contentIs('application/octet-stream'));
240
- const isFormData = () => init('isFormData', () => contentIs('multipart/form-data'));
241
- const isUrlencoded = () => init('isUrlencoded', () => contentIs('application/x-www-form-urlencoded'));
242
- const isCompressed = () => init('isCompressed', () => {
243
- const parts = contentEncodings();
244
- for (const p of parts) {
245
- if (['deflate', 'gzip', 'br'].includes(p))
246
- return true;
247
- }
248
- return false;
249
- });
250
- const contentEncodings = () => init('contentEncodings', () => (contentEncoding || '')
251
- .split(',')
252
- .map((p) => p.trim())
253
- .filter((p) => !!p));
254
- const parseBody = () => init('parsed', () => __awaiter(this, void 0, void 0, function* () {
255
- const body = yield uncompressBody(contentEncodings(), (yield rawBody()).toString());
256
- if (isJson())
257
- return jsonParser(body);
258
- else if (isFormData())
259
- return formDataParser(body);
260
- else if (isUrlencoded())
261
- return urlEncodedParser(body);
262
- else if (isBinary())
263
- return textParser(body);
264
- else
265
- return textParser(body);
266
- }));
267
- function jsonParser(v) {
268
- try {
269
- return JSON.parse(v);
270
- }
271
- catch (e) {
272
- throw new HttpError(400, e.message);
273
- }
274
- }
275
- function textParser(v) {
276
- return v;
277
- }
278
- function formDataParser(v) {
279
- const boundary = '--' +
280
- (/boundary=([^;]+)(?:;|$)/.exec(contentType || '') || [, ''])[1];
281
- if (!boundary)
282
- throw new HttpError(EHttpStatusCode.BadRequest, 'form-data boundary not recognized');
283
- const parts = v.trim().split(boundary);
284
- const result = {};
285
- let key = '';
286
- let partContentType = 'text/plain';
287
- for (const part of parts) {
288
- parsePart();
289
- key = '';
290
- partContentType = 'text/plain';
291
- let valueMode = false;
292
- const lines = part
293
- .trim()
294
- .split(/\n/g)
295
- .map((s) => s.trim());
296
- for (const line of lines) {
297
- if (valueMode) {
298
- if (!result[key]) {
299
- result[key] = line;
300
- }
301
- else {
302
- result[key] += '\n' + line;
303
- }
304
- }
305
- else {
306
- if (!line || line === '--') {
307
- valueMode = !!key;
308
- if (valueMode) {
309
- key = key.replace(/^["']/, '').replace(/["']$/, '');
310
- }
311
- continue;
312
- }
313
- if (line
314
- .toLowerCase()
315
- .startsWith('content-disposition: form-data;')) {
316
- key = (/name=([^;]+)/.exec(line) || [])[1];
317
- if (!key)
318
- throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read multipart name: ' + line);
319
- continue;
320
- }
321
- if (line.toLowerCase().startsWith('content-type:')) {
322
- partContentType = (/content-type:\s?([^;]+)/i.exec(line) || [])[1];
323
- if (!partContentType)
324
- throw new HttpError(EHttpStatusCode.BadRequest, 'Could not read content-type: ' + line);
325
- continue;
326
- }
327
- }
328
- }
329
- }
330
- parsePart();
331
- function parsePart() {
332
- if (key) {
333
- if (partContentType.indexOf('application/json') >= 0) {
334
- result[key] = JSON.parse(result[key]);
335
- }
336
- }
337
- }
338
- return result;
339
- }
340
- function urlEncodedParser(v) {
341
- return new WooksURLSearchParams(v.trim()).toJson();
342
- }
343
- return {
344
- isJson,
345
- isHtml,
346
- isXml,
347
- isText,
348
- isBinary,
349
- isFormData,
350
- isUrlencoded,
351
- isCompressed,
352
- contentEncodings,
353
- parseBody,
354
- rawBody,
355
- };
305
+ /**
306
+ * Hook to the Response Status
307
+ * @decorator
308
+ * @paramType TStatusHook
309
+ */
310
+ const StatusHook = () => Resolve((metas, level) => {
311
+ const hook = useStatus();
312
+ if (level === 'PARAM') {
313
+ return hook;
314
+ }
315
+ if (level === 'PROP' && metas.instance && metas.key) {
316
+ const initialValue = metas.instance[metas.key];
317
+ attachHook(metas.instance, {
318
+ get: () => hook.value,
319
+ set: (v) => (hook.value = v),
320
+ }, metas.key);
321
+ return typeof initialValue === 'number' ? initialValue : 200;
322
+ }
323
+ }, 'statusCode');
324
+ /**
325
+ * Hook to the Response Header
326
+ * @decorator
327
+ * @param name - header name
328
+ * @paramType THeaderHook
329
+ */
330
+ const HeaderHook = (name) => Resolve((metas, level) => {
331
+ const hook = useSetHeader(name);
332
+ if (level === 'PARAM') {
333
+ return hook;
334
+ }
335
+ if (level === 'PROP' && metas.instance && metas.key) {
336
+ const initialValue = metas.instance[metas.key];
337
+ attachHook(metas.instance, {
338
+ get: () => hook.value,
339
+ set: (v) => (hook.value = v),
340
+ }, metas.key);
341
+ return typeof initialValue === 'string' ? initialValue : '';
342
+ }
343
+ }, name);
344
+ /**
345
+ * Hook to the Response Cookie
346
+ * @decorator
347
+ * @param name - cookie name
348
+ * @paramType TCookieHook
349
+ */
350
+ const CookieHook = (name) => Resolve((metas, level) => {
351
+ const hook = useSetCookie(name);
352
+ if (level === 'PARAM') {
353
+ return hook;
354
+ }
355
+ if (level === 'PROP' && metas.instance && metas.key) {
356
+ const initialValue = metas.instance[metas.key];
357
+ attachHook(metas.instance, {
358
+ get: () => hook.value,
359
+ set: (v) => (hook.value = v),
360
+ }, metas.key);
361
+ return typeof initialValue === 'string' ? initialValue : '';
362
+ }
363
+ }, name);
364
+ /**
365
+ * Hook to the Response Cookie Attributes
366
+ * @decorator
367
+ * @param name - cookie name
368
+ * @paramType TCookieAttributes
369
+ */
370
+ const CookieAttrsHook = (name) => Resolve((metas, level) => {
371
+ const hook = useSetCookie(name);
372
+ if (level === 'PARAM') {
373
+ return attachHook({}, {
374
+ get: () => hook.attrs,
375
+ set: (v) => (hook.attrs = v),
376
+ });
377
+ }
378
+ if (level === 'PROP' && metas.instance && metas.key) {
379
+ const initialValue = metas.instance[metas.key];
380
+ attachHook(metas.instance, {
381
+ get: () => hook.attrs,
382
+ set: (v) => (hook.attrs = v),
383
+ }, metas.key);
384
+ return typeof initialValue === 'object' ? initialValue : {};
385
+ }
386
+ }, name);
387
+ /**
388
+ * Parse Authorisation Header
389
+ * @decorator
390
+ * @param name - define what to take from the Auth header
391
+ * @paramType string
392
+ */
393
+ function Authorization(name) {
394
+ return Resolve(() => {
395
+ const auth = useAuthorization();
396
+ switch (name) {
397
+ case 'username':
398
+ return auth.isBasic()
399
+ ? auth.basicCredentials()?.username
400
+ : undefined;
401
+ case 'password':
402
+ return auth.isBasic()
403
+ ? auth.basicCredentials()?.password
404
+ : undefined;
405
+ case 'bearer':
406
+ return auth.isBearer() ? auth.authorization : undefined;
407
+ case 'raw':
408
+ return auth.authRawCredentials();
409
+ case 'type':
410
+ return auth.authType();
411
+ }
412
+ }, 'authorization');
356
413
  }
357
-
358
- /**
359
- * Hook to the Response Status
360
- * @decorator
361
- * @paramType TStatusHook
362
- */
363
- const StatusHook = () => Resolve((metas, level) => {
364
- const hook = useStatus();
365
- if (level === 'PARAM') {
366
- return hook;
367
- }
368
- if (level === 'PROP' && metas.instance && metas.key) {
369
- const initialValue = metas.instance[metas.key];
370
- attachHook(metas.instance, {
371
- get: () => hook.value,
372
- set: (v) => (hook.value = v),
373
- }, metas.key);
374
- return typeof initialValue === 'number' ? initialValue : 200;
375
- }
376
- }, 'statusCode');
377
- /**
378
- * Hook to the Response Header
379
- * @decorator
380
- * @param name - header name
381
- * @paramType THeaderHook
382
- */
383
- const HeaderHook = (name) => Resolve((metas, level) => {
384
- const hook = useSetHeader(name);
385
- if (level === 'PARAM') {
386
- return hook;
387
- }
388
- if (level === 'PROP' && metas.instance && metas.key) {
389
- const initialValue = metas.instance[metas.key];
390
- attachHook(metas.instance, {
391
- get: () => hook.value,
392
- set: (v) => (hook.value = v),
393
- }, metas.key);
394
- return typeof initialValue === 'string' ? initialValue : '';
395
- }
396
- }, name);
397
- /**
398
- * Hook to the Response Cookie
399
- * @decorator
400
- * @param name - cookie name
401
- * @paramType TCookieHook
402
- */
403
- const CookieHook = (name) => Resolve((metas, level) => {
404
- const hook = useSetCookie(name);
405
- if (level === 'PARAM') {
406
- return hook;
407
- }
408
- if (level === 'PROP' && metas.instance && metas.key) {
409
- const initialValue = metas.instance[metas.key];
410
- attachHook(metas.instance, {
411
- get: () => hook.value,
412
- set: (v) => (hook.value = v),
413
- }, metas.key);
414
- return typeof initialValue === 'string' ? initialValue : '';
415
- }
416
- }, name);
417
- /**
418
- * Hook to the Response Cookie Attributes
419
- * @decorator
420
- * @param name - cookie name
421
- * @paramType TCookieAttributes
422
- */
423
- const CookieAttrsHook = (name) => Resolve((metas, level) => {
424
- const hook = useSetCookie(name);
425
- if (level === 'PARAM') {
426
- return attachHook({}, {
427
- get: () => hook.attrs,
428
- set: (v) => (hook.attrs = v),
429
- });
430
- }
431
- if (level === 'PROP' && metas.instance && metas.key) {
432
- const initialValue = metas.instance[metas.key];
433
- attachHook(metas.instance, {
434
- get: () => hook.attrs,
435
- set: (v) => (hook.attrs = v),
436
- }, metas.key);
437
- return typeof initialValue === 'object' ? initialValue : {};
438
- }
439
- }, name);
440
- /**
441
- * Parse Authorisation Header
442
- * @decorator
443
- * @param name - define what to take from the Auth header
444
- * @paramType string
445
- */
446
- function Authorization(name) {
447
- return Resolve(() => {
448
- var _a, _b;
449
- const auth = useAuthorization();
450
- switch (name) {
451
- case 'username':
452
- return auth.isBasic()
453
- ? (_a = auth.basicCredentials()) === null || _a === void 0 ? void 0 : _a.username
454
- : undefined;
455
- case 'password':
456
- return auth.isBasic()
457
- ? (_b = auth.basicCredentials()) === null || _b === void 0 ? void 0 : _b.password
458
- : undefined;
459
- case 'bearer':
460
- return auth.isBearer() ? auth.authorization : undefined;
461
- case 'raw':
462
- return auth.authRawCredentials();
463
- case 'type':
464
- return auth.authType();
465
- }
466
- }, 'authorization');
467
- }
468
- /**
469
- * Get Request Header Value
470
- * @decorator
471
- * @param name - header name
472
- * @paramType string
473
- */
474
- function Header(name) {
475
- return Resolve(() => {
476
- const headers = useHeaders();
477
- return headers[name];
478
- }, 'header: ' + name);
479
- }
480
- /**
481
- * Get Request Cookie Value
482
- * @decorator
483
- * @param name - cookie name
484
- * @paramType string
485
- */
486
- function Cookie(name) {
487
- return Resolve(() => useCookies().getCookie(name), 'cookie: ' + name);
488
- }
489
- /**
490
- * Get Query Item value or the whole parsed Query as an object
491
- * @decorator
492
- * @param name - query item name (optional)
493
- * @paramType string | object
494
- */
495
- function Query(name) {
496
- const isItem = !!name;
497
- const _name = isItem ? name : 'Query';
498
- return getMoostMate().apply(getMoostMate().decorate('paramSource', isItem ? 'QUERY_ITEM' : 'QUERY'), getMoostMate().decorate('paramName', _name), Resolve(() => {
499
- const { jsonSearchParams, urlSearchParams } = useSearchParams();
500
- if (isItem) {
501
- const p = urlSearchParams();
502
- const value = p.get(name);
503
- return value === null ? undefined : value;
504
- }
505
- const json = jsonSearchParams();
506
- return Object.keys(json).length ? json : undefined;
507
- }, _name));
508
- }
509
- /**
510
- * Get Requested URL
511
- * @decorator
512
- * @paramType string
513
- */
514
- function Url() {
515
- return Resolve(() => useRequest().url || '', 'url');
516
- }
517
- /**
518
- * Get Requested HTTP Method
519
- * @decorator
520
- * @paramType string
521
- */
522
- function Method() {
523
- return Resolve(() => useRequest().method, 'http_method');
524
- }
525
- /**
526
- * Get Raw Request Instance
527
- * @decorator
528
- * @paramType IncomingMessage
529
- */
530
- function Req() {
531
- return Resolve(() => useRequest().rawRequest, 'request');
532
- }
533
- /**
534
- * Get Raw Response Instance
535
- * @decorator
536
- * @param opts (optional) { passthrough: boolean }
537
- * @paramType ServerResponse
538
- */
539
- function Res(opts) {
540
- return Resolve(() => useResponse().rawResponse(opts), 'response');
541
- }
542
- /**
543
- * Get Request Unique Identificator (UUID)
544
- * @decorator
545
- * @paramType string
546
- */
547
- function ReqId() {
548
- return Resolve(() => useRequest().reqId(), 'reqId');
549
- }
550
- /**
551
- * Get Request IP Address
552
- * @decorator
553
- * @paramType string
554
- */
555
- function Ip(opts) {
556
- return Resolve(() => useRequest().getIp(opts), 'ip');
557
- }
558
- /**
559
- * Get Request IP Address list
560
- * @decorator
561
- * @paramType string[]
562
- */
563
- function IpList() {
564
- return Resolve(() => useRequest().getIpList(), 'ipList');
565
- }
566
- /**
567
- * Get Parsed Request Body
568
- * @decorator
569
- * @paramType object | string | unknown
570
- */
571
- function Body() {
572
- return getMoostMate().apply(getMoostMate().decorate('paramSource', 'BODY'), Resolve(() => useBody().parseBody(), 'body'));
573
- }
574
- /**
575
- * Get Raw Request Body Buffer
576
- * @decorator
577
- * @paramType Promise<Buffer>
578
- */
579
- function RawBody() {
580
- return Resolve(() => useBody().rawBody(), 'body');
414
+ /**
415
+ * Get Request Header Value
416
+ * @decorator
417
+ * @param name - header name
418
+ * @paramType string
419
+ */
420
+ function Header(name) {
421
+ return Resolve(() => {
422
+ const headers = useHeaders();
423
+ return headers[name];
424
+ }, 'header: ' + name);
425
+ }
426
+ /**
427
+ * Get Request Cookie Value
428
+ * @decorator
429
+ * @param name - cookie name
430
+ * @paramType string
431
+ */
432
+ function Cookie(name) {
433
+ return Resolve(() => useCookies().getCookie(name), 'cookie: ' + name);
434
+ }
435
+ /**
436
+ * Get Query Item value or the whole parsed Query as an object
437
+ * @decorator
438
+ * @param name - query item name (optional)
439
+ * @paramType string | object
440
+ */
441
+ function Query(name) {
442
+ const isItem = !!name;
443
+ const _name = isItem ? name : 'Query';
444
+ return getMoostMate().apply(getMoostMate().decorate('paramSource', isItem ? 'QUERY_ITEM' : 'QUERY'), getMoostMate().decorate('paramName', _name), Resolve(() => {
445
+ const { jsonSearchParams, urlSearchParams } = useSearchParams();
446
+ if (isItem) {
447
+ const p = urlSearchParams();
448
+ const value = p.get(name);
449
+ return value === null ? undefined : value;
450
+ }
451
+ const json = jsonSearchParams();
452
+ return Object.keys(json).length ? json : undefined;
453
+ }, _name));
454
+ }
455
+ /**
456
+ * Get Requested URL
457
+ * @decorator
458
+ * @paramType string
459
+ */
460
+ function Url() {
461
+ return Resolve(() => useRequest().url || '', 'url');
462
+ }
463
+ /**
464
+ * Get Requested HTTP Method
465
+ * @decorator
466
+ * @paramType string
467
+ */
468
+ function Method() {
469
+ return Resolve(() => useRequest().method, 'http_method');
470
+ }
471
+ /**
472
+ * Get Raw Request Instance
473
+ * @decorator
474
+ * @paramType IncomingMessage
475
+ */
476
+ function Req() {
477
+ return Resolve(() => useRequest().rawRequest, 'request');
478
+ }
479
+ /**
480
+ * Get Raw Response Instance
481
+ * @decorator
482
+ * @param opts (optional) { passthrough: boolean }
483
+ * @paramType ServerResponse
484
+ */
485
+ function Res(opts) {
486
+ return Resolve(() => useResponse().rawResponse(opts), 'response');
487
+ }
488
+ /**
489
+ * Get Request Unique Identificator (UUID)
490
+ * @decorator
491
+ * @paramType string
492
+ */
493
+ function ReqId() {
494
+ return Resolve(() => useRequest().reqId(), 'reqId');
495
+ }
496
+ /**
497
+ * Get Request IP Address
498
+ * @decorator
499
+ * @paramType string
500
+ */
501
+ function Ip(opts) {
502
+ return Resolve(() => useRequest().getIp(opts), 'ip');
503
+ }
504
+ /**
505
+ * Get Request IP Address list
506
+ * @decorator
507
+ * @paramType string[]
508
+ */
509
+ function IpList() {
510
+ return Resolve(() => useRequest().getIpList(), 'ipList');
511
+ }
512
+ /**
513
+ * Get Parsed Request Body
514
+ * @decorator
515
+ * @paramType object | string | unknown
516
+ */
517
+ function Body() {
518
+ return getMoostMate().apply(getMoostMate().decorate('paramSource', 'BODY'), Resolve(() => useBody().parseBody(), 'body'));
519
+ }
520
+ /**
521
+ * Get Raw Request Body Buffer
522
+ * @decorator
523
+ * @paramType Promise<Buffer>
524
+ */
525
+ function RawBody() {
526
+ return Resolve(() => useBody().rawBody(), 'body');
581
527
  }
582
528
 
583
- const setHeaderInterceptor = (name, value, opts) => {
584
- const fn = (_before, after, onError) => {
585
- const h = useSetHeader(name);
586
- const status = useStatus();
587
- const cb = () => {
588
- if ((!h.value || (opts === null || opts === void 0 ? void 0 : opts.force)) &&
589
- (!(opts === null || opts === void 0 ? void 0 : opts.status) || opts.status === status.value)) {
590
- h.value = value;
591
- }
592
- };
593
- if ((opts === null || opts === void 0 ? void 0 : opts.when) !== 'error') {
594
- after(cb);
595
- }
596
- if ((opts === null || opts === void 0 ? void 0 : opts.when) === 'always' || (opts === null || opts === void 0 ? void 0 : opts.when) === 'error') {
597
- onError(cb);
598
- }
599
- };
600
- fn.priority = TInterceptorPriority.AFTER_ALL;
601
- return fn;
602
- };
603
- /**
604
- * Set Header for Request Handler
605
- *
606
- * ```ts
607
- * import { Get, SetHeader } from '@moostjs/event-http';
608
- * import { Controller } from 'moost';
609
- *
610
- * @Controller()
611
- * export class ExampleController {
612
- * @Get('test')
613
- * // setting header for request handler
614
- * @SetHeader('x-server', 'my-server')
615
- * testHandler() {
616
- * return '...'
617
- * }
618
- * }
619
- * ```
620
- *
621
- * ```ts
622
- * import { Get, SetHeader } from '@moostjs/event-http';
623
- * import { Controller } from 'moost';
624
- *
625
- * @Controller()
626
- * export class ExampleController {
627
- * @Get('test')
628
- * // setting header only if status = 400
629
- * @SetHeader('content-type', 'text/plain', { status: 400 })
630
- * testHandler() {
631
- * return '...'
632
- * }
633
- * }
634
- * ```
635
- *
636
- * @param name name of header
637
- * @param value value for header
638
- * @param options options { status?: number, force?: boolean }
639
- */
640
- function SetHeader(...args) {
641
- return Intercept(setHeaderInterceptor(...args));
642
- }
643
- const setCookieInterceptor = (name, value, attrs) => {
644
- const fn = (before, after) => {
645
- const { setCookie, getCookie } = useSetCookies();
646
- after(() => {
647
- if (!getCookie(name)) {
648
- setCookie(name, value, attrs);
649
- }
650
- });
651
- };
652
- fn.priority = TInterceptorPriority.AFTER_ALL;
653
- return fn;
654
- };
655
- /**
656
- * Set Cookie for Request Handler
657
- * ```ts
658
- * import { Get, SetCookie } from '@moostjs/event-http';
659
- * import { Controller } from 'moost';
660
- *
661
- * @Controller()
662
- * export class ExampleController {
663
- * @Get('test')
664
- * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
665
- * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
666
- * testHandler() {
667
- * return '...'
668
- * }
669
- * }
670
- * ```
671
- *
672
- * @param name name of cookie
673
- * @param value value for cookie
674
- * @param attrs cookie attributes
675
- */
676
- function SetCookie(...args) {
677
- return Intercept(setCookieInterceptor(...args));
678
- }
679
- const setStatusInterceptor = (code, opts) => {
680
- return defineInterceptorFn((before, after) => {
681
- const status = useStatus();
682
- after(() => {
683
- if (!status.isDefined || (opts === null || opts === void 0 ? void 0 : opts.force)) {
684
- status.value = code;
685
- }
686
- });
687
- });
688
- };
689
- /**
690
- * Set Response Status for Request Handler
691
- *
692
- * ```ts
693
- * import { Get, SetStatus } from '@moostjs/event-http';
694
- * import { Controller } from 'moost';
695
- *
696
- * @Controller()
697
- * export class ExampleController {
698
- * @Get('test')
699
- * @SetStatus(201)
700
- * testHandler() {
701
- * return '...'
702
- * }
703
- * }
704
- * ```
705
- * @param code number
706
- * @param opts optional { force?: boolean }
707
- */
708
- function SetStatus(...args) {
709
- return Intercept(setStatusInterceptor(...args));
529
+ const setHeaderInterceptor = (name, value, opts) => {
530
+ const fn = (_before, after, onError) => {
531
+ const h = useSetHeader(name);
532
+ const status = useStatus();
533
+ const cb = () => {
534
+ if ((!h.value || opts?.force) &&
535
+ (!opts?.status || opts.status === status.value)) {
536
+ h.value = value;
537
+ }
538
+ };
539
+ if (opts?.when !== 'error') {
540
+ after(cb);
541
+ }
542
+ if (opts?.when === 'always' || opts?.when === 'error') {
543
+ onError(cb);
544
+ }
545
+ };
546
+ fn.priority = TInterceptorPriority.AFTER_ALL;
547
+ return fn;
548
+ };
549
+ /**
550
+ * Set Header for Request Handler
551
+ *
552
+ * ```ts
553
+ * import { Get, SetHeader } from '@moostjs/event-http';
554
+ * import { Controller } from 'moost';
555
+ *
556
+ * @Controller()
557
+ * export class ExampleController {
558
+ * @Get('test')
559
+ * // setting header for request handler
560
+ * @SetHeader('x-server', 'my-server')
561
+ * testHandler() {
562
+ * return '...'
563
+ * }
564
+ * }
565
+ * ```
566
+ *
567
+ * ```ts
568
+ * import { Get, SetHeader } from '@moostjs/event-http';
569
+ * import { Controller } from 'moost';
570
+ *
571
+ * @Controller()
572
+ * export class ExampleController {
573
+ * @Get('test')
574
+ * // setting header only if status = 400
575
+ * @SetHeader('content-type', 'text/plain', { status: 400 })
576
+ * testHandler() {
577
+ * return '...'
578
+ * }
579
+ * }
580
+ * ```
581
+ *
582
+ * @param name name of header
583
+ * @param value value for header
584
+ * @param options options { status?: number, force?: boolean }
585
+ */
586
+ function SetHeader(...args) {
587
+ return Intercept(setHeaderInterceptor(...args));
588
+ }
589
+ const setCookieInterceptor = (name, value, attrs) => {
590
+ const fn = (before, after) => {
591
+ const { setCookie, getCookie } = useSetCookies();
592
+ after(() => {
593
+ if (!getCookie(name)) {
594
+ setCookie(name, value, attrs);
595
+ }
596
+ });
597
+ };
598
+ fn.priority = TInterceptorPriority.AFTER_ALL;
599
+ return fn;
600
+ };
601
+ /**
602
+ * Set Cookie for Request Handler
603
+ * ```ts
604
+ * import { Get, SetCookie } from '@moostjs/event-http';
605
+ * import { Controller } from 'moost';
606
+ *
607
+ * @Controller()
608
+ * export class ExampleController {
609
+ * @Get('test')
610
+ * // setting 'my-cookie' = 'value' with maxAge of 10 minutes
611
+ * @SetCookie('my-cookie', 'value', { maxAge: '10m' })
612
+ * testHandler() {
613
+ * return '...'
614
+ * }
615
+ * }
616
+ * ```
617
+ *
618
+ * @param name name of cookie
619
+ * @param value value for cookie
620
+ * @param attrs cookie attributes
621
+ */
622
+ function SetCookie(...args) {
623
+ return Intercept(setCookieInterceptor(...args));
624
+ }
625
+ const setStatusInterceptor = (code, opts) => {
626
+ return defineInterceptorFn((before, after) => {
627
+ const status = useStatus();
628
+ after(() => {
629
+ if (!status.isDefined || opts?.force) {
630
+ status.value = code;
631
+ }
632
+ });
633
+ });
634
+ };
635
+ /**
636
+ * Set Response Status for Request Handler
637
+ *
638
+ * ```ts
639
+ * import { Get, SetStatus } from '@moostjs/event-http';
640
+ * import { Controller } from 'moost';
641
+ *
642
+ * @Controller()
643
+ * export class ExampleController {
644
+ * @Get('test')
645
+ * @SetStatus(201)
646
+ * testHandler() {
647
+ * return '...'
648
+ * }
649
+ * }
650
+ * ```
651
+ * @param code number
652
+ * @param opts optional { force?: boolean }
653
+ */
654
+ function SetStatus(...args) {
655
+ return Intercept(setStatusInterceptor(...args));
710
656
  }
711
657
 
712
658
  export { All, Authorization, Body, Cookie, CookieAttrsHook, CookieHook, Delete, Get, Header, HeaderHook, HttpMethod, Ip, IpList, Method, MoostHttp, Patch, Post, Put, Query, RawBody, Req, ReqId, Res, SetCookie, SetHeader, SetStatus, StatusHook, Url };