@wooksjs/event-http 0.7.11 → 0.7.13
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.cjs +172 -179
- package/dist/index.mjs +98 -111
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
9
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
@@ -21,23 +26,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
26
|
}) : target, mod));
|
|
22
27
|
|
|
23
28
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
let _wooksjs_event_core = require("@wooksjs/event-core");
|
|
30
|
+
let buffer = require("buffer");
|
|
31
|
+
let node_stream = require("node:stream");
|
|
32
|
+
let node_util = require("node:util");
|
|
33
|
+
let node_zlib = require("node:zlib");
|
|
34
|
+
let url = require("url");
|
|
35
|
+
let http = require("http");
|
|
36
|
+
http = __toESM(http);
|
|
37
|
+
let stream = require("stream");
|
|
38
|
+
let wooks = require("wooks");
|
|
39
|
+
let net = require("net");
|
|
34
40
|
|
|
35
41
|
//#region packages/event-http/src/http-kind.ts
|
|
36
42
|
/** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
|
|
37
|
-
const httpKind = (0,
|
|
38
|
-
req: (0,
|
|
39
|
-
response: (0,
|
|
40
|
-
requestLimits: (0,
|
|
43
|
+
const httpKind = (0, _wooksjs_event_core.defineEventKind)("http", {
|
|
44
|
+
req: (0, _wooksjs_event_core.slot)(),
|
|
45
|
+
response: (0, _wooksjs_event_core.slot)(),
|
|
46
|
+
requestLimits: (0, _wooksjs_event_core.slot)()
|
|
41
47
|
});
|
|
42
48
|
|
|
43
49
|
//#endregion
|
|
@@ -68,7 +74,7 @@ function getCookieRegExp(name) {
|
|
|
68
74
|
}
|
|
69
75
|
return re;
|
|
70
76
|
}
|
|
71
|
-
const parseCookieValue = (0,
|
|
77
|
+
const parseCookieValue = (0, _wooksjs_event_core.cachedBy)((name, ctx) => {
|
|
72
78
|
const cookie = ctx.get(httpKind.keys.req).headers.cookie;
|
|
73
79
|
if (cookie) {
|
|
74
80
|
const result = getCookieRegExp(name).exec(cookie);
|
|
@@ -84,7 +90,7 @@ const parseCookieValue = (0, __wooksjs_event_core.cachedBy)((name, ctx) => {
|
|
|
84
90
|
* const sessionId = getCookie('session_id')
|
|
85
91
|
* ```
|
|
86
92
|
*/
|
|
87
|
-
const useCookies = (0,
|
|
93
|
+
const useCookies = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
88
94
|
raw: ctx.get(httpKind.keys.req).headers.cookie,
|
|
89
95
|
getCookie: (name) => parseCookieValue(name, ctx)
|
|
90
96
|
}));
|
|
@@ -97,23 +103,22 @@ const ACCEPT_TYPE_MAP = {
|
|
|
97
103
|
xml: "application/xml",
|
|
98
104
|
text: "text/plain"
|
|
99
105
|
};
|
|
100
|
-
const acceptsMime = (0,
|
|
106
|
+
const acceptsMime = (0, _wooksjs_event_core.cachedBy)((type, ctx) => {
|
|
101
107
|
const accept = ctx.get(httpKind.keys.req).headers.accept;
|
|
102
108
|
const mime = ACCEPT_TYPE_MAP[type] || type;
|
|
103
109
|
return !!(accept && (accept === "*/*" || accept.includes(mime)));
|
|
104
110
|
});
|
|
105
111
|
/** Provides helpers to check the request's Accept header for supported MIME types. */
|
|
106
|
-
const useAccept = (0,
|
|
107
|
-
const accept = ctx.get(httpKind.keys.req).headers.accept;
|
|
112
|
+
const useAccept = (0, _wooksjs_event_core.defineWook)((ctx) => {
|
|
108
113
|
return {
|
|
109
|
-
accept,
|
|
114
|
+
accept: ctx.get(httpKind.keys.req).headers.accept,
|
|
110
115
|
has: (type) => acceptsMime(type, ctx)
|
|
111
116
|
};
|
|
112
117
|
});
|
|
113
118
|
|
|
114
119
|
//#endregion
|
|
115
120
|
//#region packages/event-http/src/composables/header-authorization.ts
|
|
116
|
-
const authTypeSlot = (0,
|
|
121
|
+
const authTypeSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
117
122
|
const authorization = ctx.get(httpKind.keys.req).headers.authorization;
|
|
118
123
|
if (authorization) {
|
|
119
124
|
const space = authorization.indexOf(" ");
|
|
@@ -121,7 +126,7 @@ const authTypeSlot = (0, __wooksjs_event_core.cached)((ctx) => {
|
|
|
121
126
|
}
|
|
122
127
|
return null;
|
|
123
128
|
});
|
|
124
|
-
const authCredentialsSlot = (0,
|
|
129
|
+
const authCredentialsSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
125
130
|
const authorization = ctx.get(httpKind.keys.req).headers.authorization;
|
|
126
131
|
if (authorization) {
|
|
127
132
|
const space = authorization.indexOf(" ");
|
|
@@ -129,13 +134,10 @@ const authCredentialsSlot = (0, __wooksjs_event_core.cached)((ctx) => {
|
|
|
129
134
|
}
|
|
130
135
|
return null;
|
|
131
136
|
});
|
|
132
|
-
const basicCredentialsSlot = (0,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (type?.toLocaleLowerCase() === "basic") {
|
|
137
|
-
const creds = buffer.Buffer.from(ctx.get(authCredentialsSlot) || "", "base64").toString("ascii");
|
|
138
|
-
const [username, password] = creds.split(":");
|
|
137
|
+
const basicCredentialsSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
138
|
+
if (ctx.get(httpKind.keys.req).headers.authorization) {
|
|
139
|
+
if (ctx.get(authTypeSlot)?.toLocaleLowerCase() === "basic") {
|
|
140
|
+
const [username, password] = buffer.Buffer.from(ctx.get(authCredentialsSlot) || "", "base64").toString("ascii").split(":");
|
|
139
141
|
return {
|
|
140
142
|
username,
|
|
141
143
|
password
|
|
@@ -144,9 +146,8 @@ const basicCredentialsSlot = (0, __wooksjs_event_core.cached)((ctx) => {
|
|
|
144
146
|
}
|
|
145
147
|
return null;
|
|
146
148
|
});
|
|
147
|
-
const authIsSlot = (0,
|
|
148
|
-
|
|
149
|
-
return authType?.toLowerCase() === type.toLowerCase();
|
|
149
|
+
const authIsSlot = (0, _wooksjs_event_core.cachedBy)((type, ctx) => {
|
|
150
|
+
return ctx.get(authTypeSlot)?.toLowerCase() === type.toLowerCase();
|
|
150
151
|
});
|
|
151
152
|
/**
|
|
152
153
|
* Provides parsed access to the Authorization header (type, credentials, Basic decoding).
|
|
@@ -156,10 +157,9 @@ const authIsSlot = (0, __wooksjs_event_core.cachedBy)((type, ctx) => {
|
|
|
156
157
|
* if (is('bearer')) { const token = credentials() }
|
|
157
158
|
* ```
|
|
158
159
|
*/
|
|
159
|
-
const useAuthorization = (0,
|
|
160
|
-
const authorization = ctx.get(httpKind.keys.req).headers.authorization;
|
|
160
|
+
const useAuthorization = (0, _wooksjs_event_core.defineWook)((ctx) => {
|
|
161
161
|
return {
|
|
162
|
-
authorization,
|
|
162
|
+
authorization: ctx.get(httpKind.keys.req).headers.authorization,
|
|
163
163
|
type: () => ctx.get(authTypeSlot),
|
|
164
164
|
credentials: () => ctx.get(authCredentialsSlot),
|
|
165
165
|
is: (type) => authIsSlot(type, ctx),
|
|
@@ -312,84 +312,84 @@ const httpStatusCodes = {
|
|
|
312
312
|
511: "Network Authentication Required"
|
|
313
313
|
};
|
|
314
314
|
/** Enum of all standard HTTP status codes (100–511). */
|
|
315
|
-
let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode
|
|
316
|
-
EHttpStatusCode
|
|
317
|
-
EHttpStatusCode
|
|
318
|
-
EHttpStatusCode
|
|
319
|
-
EHttpStatusCode
|
|
320
|
-
EHttpStatusCode
|
|
321
|
-
EHttpStatusCode
|
|
322
|
-
EHttpStatusCode
|
|
323
|
-
EHttpStatusCode
|
|
324
|
-
EHttpStatusCode
|
|
325
|
-
EHttpStatusCode
|
|
326
|
-
EHttpStatusCode
|
|
327
|
-
EHttpStatusCode
|
|
328
|
-
EHttpStatusCode
|
|
329
|
-
EHttpStatusCode
|
|
330
|
-
EHttpStatusCode
|
|
331
|
-
EHttpStatusCode
|
|
332
|
-
EHttpStatusCode
|
|
333
|
-
EHttpStatusCode
|
|
334
|
-
EHttpStatusCode
|
|
335
|
-
EHttpStatusCode
|
|
336
|
-
EHttpStatusCode
|
|
337
|
-
EHttpStatusCode
|
|
338
|
-
EHttpStatusCode
|
|
339
|
-
EHttpStatusCode
|
|
340
|
-
EHttpStatusCode
|
|
341
|
-
EHttpStatusCode
|
|
342
|
-
EHttpStatusCode
|
|
343
|
-
EHttpStatusCode
|
|
344
|
-
EHttpStatusCode
|
|
345
|
-
EHttpStatusCode
|
|
346
|
-
EHttpStatusCode
|
|
347
|
-
EHttpStatusCode
|
|
348
|
-
EHttpStatusCode
|
|
349
|
-
EHttpStatusCode
|
|
350
|
-
EHttpStatusCode
|
|
351
|
-
EHttpStatusCode
|
|
352
|
-
EHttpStatusCode
|
|
353
|
-
EHttpStatusCode
|
|
354
|
-
EHttpStatusCode
|
|
355
|
-
EHttpStatusCode
|
|
356
|
-
EHttpStatusCode
|
|
357
|
-
EHttpStatusCode
|
|
358
|
-
EHttpStatusCode
|
|
359
|
-
EHttpStatusCode
|
|
360
|
-
EHttpStatusCode
|
|
361
|
-
EHttpStatusCode
|
|
362
|
-
EHttpStatusCode
|
|
363
|
-
EHttpStatusCode
|
|
364
|
-
EHttpStatusCode
|
|
365
|
-
EHttpStatusCode
|
|
366
|
-
EHttpStatusCode
|
|
367
|
-
EHttpStatusCode
|
|
368
|
-
EHttpStatusCode
|
|
369
|
-
EHttpStatusCode
|
|
370
|
-
EHttpStatusCode
|
|
371
|
-
EHttpStatusCode
|
|
372
|
-
EHttpStatusCode
|
|
373
|
-
EHttpStatusCode
|
|
374
|
-
EHttpStatusCode
|
|
375
|
-
EHttpStatusCode
|
|
376
|
-
EHttpStatusCode
|
|
377
|
-
EHttpStatusCode
|
|
378
|
-
EHttpStatusCode
|
|
379
|
-
return EHttpStatusCode
|
|
315
|
+
let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode) {
|
|
316
|
+
EHttpStatusCode[EHttpStatusCode["Continue"] = 100] = "Continue";
|
|
317
|
+
EHttpStatusCode[EHttpStatusCode["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
318
|
+
EHttpStatusCode[EHttpStatusCode["Processing"] = 102] = "Processing";
|
|
319
|
+
EHttpStatusCode[EHttpStatusCode["EarlyHints"] = 103] = "EarlyHints";
|
|
320
|
+
EHttpStatusCode[EHttpStatusCode["OK"] = 200] = "OK";
|
|
321
|
+
EHttpStatusCode[EHttpStatusCode["Created"] = 201] = "Created";
|
|
322
|
+
EHttpStatusCode[EHttpStatusCode["Accepted"] = 202] = "Accepted";
|
|
323
|
+
EHttpStatusCode[EHttpStatusCode["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
324
|
+
EHttpStatusCode[EHttpStatusCode["NoContent"] = 204] = "NoContent";
|
|
325
|
+
EHttpStatusCode[EHttpStatusCode["ResetContent"] = 205] = "ResetContent";
|
|
326
|
+
EHttpStatusCode[EHttpStatusCode["PartialContent"] = 206] = "PartialContent";
|
|
327
|
+
EHttpStatusCode[EHttpStatusCode["MultiStatus"] = 207] = "MultiStatus";
|
|
328
|
+
EHttpStatusCode[EHttpStatusCode["AlreadyReported"] = 208] = "AlreadyReported";
|
|
329
|
+
EHttpStatusCode[EHttpStatusCode["IMUsed"] = 226] = "IMUsed";
|
|
330
|
+
EHttpStatusCode[EHttpStatusCode["MultipleChoices"] = 300] = "MultipleChoices";
|
|
331
|
+
EHttpStatusCode[EHttpStatusCode["MovedPermanently"] = 301] = "MovedPermanently";
|
|
332
|
+
EHttpStatusCode[EHttpStatusCode["Found"] = 302] = "Found";
|
|
333
|
+
EHttpStatusCode[EHttpStatusCode["SeeOther"] = 303] = "SeeOther";
|
|
334
|
+
EHttpStatusCode[EHttpStatusCode["NotModified"] = 304] = "NotModified";
|
|
335
|
+
EHttpStatusCode[EHttpStatusCode["UseProxy"] = 305] = "UseProxy";
|
|
336
|
+
EHttpStatusCode[EHttpStatusCode["SwitchProxy"] = 306] = "SwitchProxy";
|
|
337
|
+
EHttpStatusCode[EHttpStatusCode["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
338
|
+
EHttpStatusCode[EHttpStatusCode["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
339
|
+
EHttpStatusCode[EHttpStatusCode["BadRequest"] = 400] = "BadRequest";
|
|
340
|
+
EHttpStatusCode[EHttpStatusCode["Unauthorized"] = 401] = "Unauthorized";
|
|
341
|
+
EHttpStatusCode[EHttpStatusCode["PaymentRequired"] = 402] = "PaymentRequired";
|
|
342
|
+
EHttpStatusCode[EHttpStatusCode["Forbidden"] = 403] = "Forbidden";
|
|
343
|
+
EHttpStatusCode[EHttpStatusCode["NotFound"] = 404] = "NotFound";
|
|
344
|
+
EHttpStatusCode[EHttpStatusCode["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
345
|
+
EHttpStatusCode[EHttpStatusCode["NotAcceptable"] = 406] = "NotAcceptable";
|
|
346
|
+
EHttpStatusCode[EHttpStatusCode["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
347
|
+
EHttpStatusCode[EHttpStatusCode["RequestTimeout"] = 408] = "RequestTimeout";
|
|
348
|
+
EHttpStatusCode[EHttpStatusCode["Conflict"] = 409] = "Conflict";
|
|
349
|
+
EHttpStatusCode[EHttpStatusCode["Gone"] = 410] = "Gone";
|
|
350
|
+
EHttpStatusCode[EHttpStatusCode["LengthRequired"] = 411] = "LengthRequired";
|
|
351
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
352
|
+
EHttpStatusCode[EHttpStatusCode["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
353
|
+
EHttpStatusCode[EHttpStatusCode["URITooLong"] = 414] = "URITooLong";
|
|
354
|
+
EHttpStatusCode[EHttpStatusCode["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
355
|
+
EHttpStatusCode[EHttpStatusCode["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
356
|
+
EHttpStatusCode[EHttpStatusCode["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
357
|
+
EHttpStatusCode[EHttpStatusCode["ImATeapot"] = 418] = "ImATeapot";
|
|
358
|
+
EHttpStatusCode[EHttpStatusCode["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
359
|
+
EHttpStatusCode[EHttpStatusCode["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
360
|
+
EHttpStatusCode[EHttpStatusCode["Locked"] = 423] = "Locked";
|
|
361
|
+
EHttpStatusCode[EHttpStatusCode["FailedDependency"] = 424] = "FailedDependency";
|
|
362
|
+
EHttpStatusCode[EHttpStatusCode["TooEarly"] = 425] = "TooEarly";
|
|
363
|
+
EHttpStatusCode[EHttpStatusCode["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
364
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
365
|
+
EHttpStatusCode[EHttpStatusCode["TooManyRequests"] = 429] = "TooManyRequests";
|
|
366
|
+
EHttpStatusCode[EHttpStatusCode["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
367
|
+
EHttpStatusCode[EHttpStatusCode["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
368
|
+
EHttpStatusCode[EHttpStatusCode["InternalServerError"] = 500] = "InternalServerError";
|
|
369
|
+
EHttpStatusCode[EHttpStatusCode["NotImplemented"] = 501] = "NotImplemented";
|
|
370
|
+
EHttpStatusCode[EHttpStatusCode["BadGateway"] = 502] = "BadGateway";
|
|
371
|
+
EHttpStatusCode[EHttpStatusCode["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
372
|
+
EHttpStatusCode[EHttpStatusCode["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
373
|
+
EHttpStatusCode[EHttpStatusCode["HTTPVersionNotSupported"] = 505] = "HTTPVersionNotSupported";
|
|
374
|
+
EHttpStatusCode[EHttpStatusCode["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
375
|
+
EHttpStatusCode[EHttpStatusCode["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
376
|
+
EHttpStatusCode[EHttpStatusCode["LoopDetected"] = 508] = "LoopDetected";
|
|
377
|
+
EHttpStatusCode[EHttpStatusCode["NotExtended"] = 510] = "NotExtended";
|
|
378
|
+
EHttpStatusCode[EHttpStatusCode["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
379
|
+
return EHttpStatusCode;
|
|
380
380
|
}({});
|
|
381
381
|
|
|
382
382
|
//#endregion
|
|
383
383
|
//#region packages/event-http/src/errors/http-error.ts
|
|
384
384
|
/** Represents an HTTP error with a status code and optional structured body. */
|
|
385
385
|
var HttpError = class extends Error {
|
|
386
|
-
name = "HttpError";
|
|
387
386
|
constructor(code = 500, _body = "") {
|
|
388
387
|
const prev = Error.stackTraceLimit;
|
|
389
388
|
Error.stackTraceLimit = 0;
|
|
390
389
|
super(typeof _body === "string" ? _body : _body.message);
|
|
391
390
|
this.code = code;
|
|
392
391
|
this._body = _body;
|
|
392
|
+
this.name = "HttpError";
|
|
393
393
|
Error.stackTraceLimit = prev;
|
|
394
394
|
}
|
|
395
395
|
get body() {
|
|
@@ -416,12 +416,10 @@ const DEFAULT_LIMITS = {
|
|
|
416
416
|
maxRatio: 100,
|
|
417
417
|
readTimeoutMs: 1e4
|
|
418
418
|
};
|
|
419
|
-
const contentEncodingsSlot = (0,
|
|
420
|
-
|
|
421
|
-
const contentEncoding = req.headers["content-encoding"];
|
|
422
|
-
return (contentEncoding || "").split(",").map((p) => p.trim()).filter((p) => !!p);
|
|
419
|
+
const contentEncodingsSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
420
|
+
return (ctx.get(httpKind.keys.req).headers["content-encoding"] || "").split(",").map((p) => p.trim()).filter((p) => !!p);
|
|
423
421
|
});
|
|
424
|
-
const isCompressedSlot = (0,
|
|
422
|
+
const isCompressedSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
425
423
|
const parts = ctx.get(contentEncodingsSlot);
|
|
426
424
|
for (const p of parts) if ([
|
|
427
425
|
"deflate",
|
|
@@ -431,7 +429,7 @@ const isCompressedSlot = (0, __wooksjs_event_core.cached)((ctx) => {
|
|
|
431
429
|
return false;
|
|
432
430
|
});
|
|
433
431
|
/** @internal Exported for test pre-seeding via `ctx.set(rawBodySlot, ...)`. */
|
|
434
|
-
const rawBodySlot = (0,
|
|
432
|
+
const rawBodySlot = (0, _wooksjs_event_core.cached)(async (ctx) => {
|
|
435
433
|
const req = ctx.get(httpKind.keys.req);
|
|
436
434
|
const encs = ctx.get(contentEncodingsSlot);
|
|
437
435
|
const isZip = ctx.get(isCompressedSlot);
|
|
@@ -477,12 +475,12 @@ const rawBodySlot = (0, __wooksjs_event_core.cached)(async (ctx) => {
|
|
|
477
475
|
clearTimer();
|
|
478
476
|
}
|
|
479
477
|
}
|
|
480
|
-
let stream
|
|
481
|
-
if (streamable) stream
|
|
478
|
+
let stream = limitedCompressed();
|
|
479
|
+
if (streamable) stream = await uncompressBodyStream(encs, stream);
|
|
482
480
|
const chunks = [];
|
|
483
481
|
let inflatedBytes = 0;
|
|
484
482
|
try {
|
|
485
|
-
for await (const chunk of stream
|
|
483
|
+
for await (const chunk of stream) {
|
|
486
484
|
inflatedBytes += chunk.length;
|
|
487
485
|
if (inflatedBytes > maxInflated) throw new HttpError(413, "Inflated body too large");
|
|
488
486
|
chunks.push(chunk);
|
|
@@ -500,16 +498,16 @@ const rawBodySlot = (0, __wooksjs_event_core.cached)(async (ctx) => {
|
|
|
500
498
|
if (isZip && rawBytes > 0 && inflatedBytes / rawBytes > maxRatio) throw new HttpError(413, "Compression ratio too high");
|
|
501
499
|
return body;
|
|
502
500
|
});
|
|
503
|
-
const forwardedIpSlot = (0,
|
|
501
|
+
const forwardedIpSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
504
502
|
const req = ctx.get(httpKind.keys.req);
|
|
505
503
|
if (typeof req.headers[xForwardedFor] === "string" && req.headers[xForwardedFor]) return req.headers[xForwardedFor].split(",").shift()?.trim();
|
|
506
504
|
return "";
|
|
507
505
|
});
|
|
508
|
-
const remoteIpSlot = (0,
|
|
506
|
+
const remoteIpSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
509
507
|
const req = ctx.get(httpKind.keys.req);
|
|
510
508
|
return req.socket.remoteAddress || req.connection.remoteAddress || "";
|
|
511
509
|
});
|
|
512
|
-
const ipListSlot = (0,
|
|
510
|
+
const ipListSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
513
511
|
const req = ctx.get(httpKind.keys.req);
|
|
514
512
|
return {
|
|
515
513
|
remoteIp: req.socket.remoteAddress || req.connection.remoteAddress || "",
|
|
@@ -524,7 +522,7 @@ const ipListSlot = (0, __wooksjs_event_core.cached)((ctx) => {
|
|
|
524
522
|
* const body = await rawBody()
|
|
525
523
|
* ```
|
|
526
524
|
*/
|
|
527
|
-
const useRequest = (0,
|
|
525
|
+
const useRequest = (0, _wooksjs_event_core.defineWook)((ctx) => {
|
|
528
526
|
const req = ctx.get(httpKind.keys.req);
|
|
529
527
|
const limits = () => ctx.get(httpKind.keys.requestLimits);
|
|
530
528
|
const setLimit = (limitKey, value) => {
|
|
@@ -556,7 +554,7 @@ const useRequest = (0, __wooksjs_event_core.defineWook)((ctx) => {
|
|
|
556
554
|
method: req.method,
|
|
557
555
|
headers: req.headers,
|
|
558
556
|
rawBody: () => ctx.get(rawBodySlot),
|
|
559
|
-
reqId: (0,
|
|
557
|
+
reqId: (0, _wooksjs_event_core.useEventId)(ctx).getId,
|
|
560
558
|
getIp,
|
|
561
559
|
getIpList: () => ctx.get(ipListSlot),
|
|
562
560
|
isCompressed: () => ctx.get(isCompressedSlot),
|
|
@@ -600,7 +598,7 @@ function useHeaders(ctx) {
|
|
|
600
598
|
* ```
|
|
601
599
|
*/
|
|
602
600
|
function useResponse(ctx) {
|
|
603
|
-
return (ctx ?? (0,
|
|
601
|
+
return (ctx ?? (0, _wooksjs_event_core.current)()).get(httpKind.keys.response);
|
|
604
602
|
}
|
|
605
603
|
|
|
606
604
|
//#endregion
|
|
@@ -620,10 +618,8 @@ var WooksURLSearchParams = class extends url.URLSearchParams {
|
|
|
620
618
|
/** Converts query parameters to a plain object. Array params (keys ending with `[]`) become `string[]`. */
|
|
621
619
|
toJson() {
|
|
622
620
|
const json = Object.create(null);
|
|
623
|
-
for (const [key, value] of this.entries()) if (isArrayParam(key))
|
|
624
|
-
|
|
625
|
-
a.push(value);
|
|
626
|
-
} else {
|
|
621
|
+
for (const [key, value] of this.entries()) if (isArrayParam(key)) (json[key] = json[key] || []).push(value);
|
|
622
|
+
else {
|
|
627
623
|
if (ILLEGAL_KEYS.has(key)) throw new HttpError(400, `Illegal key name "${key}"`);
|
|
628
624
|
if (key in json) throw new HttpError(400, `Duplicate key "${key}"`);
|
|
629
625
|
json[key] = value;
|
|
@@ -637,12 +633,12 @@ function isArrayParam(name) {
|
|
|
637
633
|
|
|
638
634
|
//#endregion
|
|
639
635
|
//#region packages/event-http/src/composables/search-params.ts
|
|
640
|
-
const rawSearchParamsSlot = (0,
|
|
641
|
-
const url
|
|
642
|
-
const i = url
|
|
643
|
-
return i >= 0 ? url
|
|
636
|
+
const rawSearchParamsSlot = (0, _wooksjs_event_core.cached)((ctx) => {
|
|
637
|
+
const url = ctx.get(httpKind.keys.req).url || "";
|
|
638
|
+
const i = url.indexOf("?");
|
|
639
|
+
return i >= 0 ? url.slice(i) : "";
|
|
644
640
|
});
|
|
645
|
-
const urlSearchParamsSlot = (0,
|
|
641
|
+
const urlSearchParamsSlot = (0, _wooksjs_event_core.cached)((ctx) => new WooksURLSearchParams(ctx.get(rawSearchParamsSlot)));
|
|
646
642
|
/**
|
|
647
643
|
* Provides access to URL search (query) parameters from the request.
|
|
648
644
|
* @example
|
|
@@ -651,7 +647,7 @@ const urlSearchParamsSlot = (0, __wooksjs_event_core.cached)((ctx) => new WooksU
|
|
|
651
647
|
* const page = params().get('page')
|
|
652
648
|
* ```
|
|
653
649
|
*/
|
|
654
|
-
const useUrlParams = (0,
|
|
650
|
+
const useUrlParams = (0, _wooksjs_event_core.defineWook)((ctx) => ({
|
|
655
651
|
raw: () => ctx.get(rawSearchParamsSlot),
|
|
656
652
|
params: () => ctx.get(urlSearchParamsSlot),
|
|
657
653
|
toJson: () => ctx.get(urlSearchParamsSlot).toJson()
|
|
@@ -661,11 +657,11 @@ const useUrlParams = (0, __wooksjs_event_core.defineWook)((ctx) => ({
|
|
|
661
657
|
//#region packages/event-http/src/event-http.ts
|
|
662
658
|
/** Creates an HTTP event context and runs `fn` inside it. */
|
|
663
659
|
function createHttpContext(options, seeds, fn) {
|
|
664
|
-
return (0,
|
|
660
|
+
return (0, _wooksjs_event_core.createEventContext)(options, httpKind, seeds, fn);
|
|
665
661
|
}
|
|
666
662
|
/** Returns the current HTTP event context. */
|
|
667
663
|
function useHttpContext(ctx) {
|
|
668
|
-
return ctx ?? (0,
|
|
664
|
+
return ctx ?? (0, _wooksjs_event_core.current)();
|
|
669
665
|
}
|
|
670
666
|
|
|
671
667
|
//#endregion
|
|
@@ -735,10 +731,10 @@ function renderCookie(key, data) {
|
|
|
735
731
|
return `${key}=${encodeURIComponent(data.value)}${attrs}`;
|
|
736
732
|
}
|
|
737
733
|
const cookieAttrFunc = {
|
|
738
|
-
expires: (v) => `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
|
|
739
|
-
maxAge: (v) => `Max-Age=${convertTime(v, "s").toString()}`,
|
|
740
|
-
domain: (v) => `Domain=${sanitizeCookieAttrValue(String(v))}`,
|
|
741
|
-
path: (v) => `Path=${sanitizeCookieAttrValue(String(v))}`,
|
|
734
|
+
expires: (v) => v === void 0 ? "" : `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
|
|
735
|
+
maxAge: (v) => v === void 0 ? "" : `Max-Age=${convertTime(v, "s").toString()}`,
|
|
736
|
+
domain: (v) => v === void 0 ? "" : `Domain=${sanitizeCookieAttrValue(String(v))}`,
|
|
737
|
+
path: (v) => v === void 0 ? "" : `Path=${sanitizeCookieAttrValue(String(v))}`,
|
|
742
738
|
secure: (v) => v ? "Secure" : "",
|
|
743
739
|
httpOnly: (v) => v ? "HttpOnly" : "",
|
|
744
740
|
sameSite: (v) => v ? `SameSite=${typeof v === "string" ? v : "Strict"}` : ""
|
|
@@ -779,15 +775,15 @@ var HttpResponse = class {
|
|
|
779
775
|
this._req = _req;
|
|
780
776
|
this._logger = _logger;
|
|
781
777
|
this._captureMode = _captureMode;
|
|
778
|
+
this._status = 0;
|
|
779
|
+
this._body = void 0;
|
|
780
|
+
this._headers = {};
|
|
781
|
+
this._cookies = {};
|
|
782
|
+
this._rawCookies = [];
|
|
783
|
+
this._hasCookies = false;
|
|
784
|
+
this._responded = false;
|
|
782
785
|
if (defaultHeaders) for (const key in defaultHeaders) this._headers[key] = defaultHeaders[key];
|
|
783
786
|
}
|
|
784
|
-
_status = 0;
|
|
785
|
-
_body = void 0;
|
|
786
|
-
_headers = {};
|
|
787
|
-
_cookies = {};
|
|
788
|
-
_rawCookies = [];
|
|
789
|
-
_hasCookies = false;
|
|
790
|
-
_responded = false;
|
|
791
787
|
/** The HTTP status code. If not set, it is inferred automatically when `send()` is called. */
|
|
792
788
|
get status() {
|
|
793
789
|
return this._status;
|
|
@@ -1461,7 +1457,7 @@ function escapeHtml(value) {
|
|
|
1461
1457
|
//#endregion
|
|
1462
1458
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1463
1459
|
let framework = {
|
|
1464
|
-
version: "0.7.
|
|
1460
|
+
version: "0.7.12",
|
|
1465
1461
|
poweredBy: "wooksjs",
|
|
1466
1462
|
link: "https://wooks.moost.org/",
|
|
1467
1463
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
@@ -1541,9 +1537,6 @@ const DEFAULT_FORWARD_HEADERS = [
|
|
|
1541
1537
|
];
|
|
1542
1538
|
/** HTTP adapter for Wooks that provides route registration, server lifecycle, and request handling. */
|
|
1543
1539
|
var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
1544
|
-
logger;
|
|
1545
|
-
ResponseClass;
|
|
1546
|
-
eventContextOptions;
|
|
1547
1540
|
constructor(opts, wooks$1) {
|
|
1548
1541
|
super(wooks$1, opts?.logger, opts?.router);
|
|
1549
1542
|
this.opts = opts;
|
|
@@ -1587,12 +1580,10 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1587
1580
|
upgrade(path, handler) {
|
|
1588
1581
|
return this.on("UPGRADE", path, handler);
|
|
1589
1582
|
}
|
|
1590
|
-
wsHandler;
|
|
1591
1583
|
/** Register a WebSocket upgrade handler that implements the WooksUpgradeHandler contract. */
|
|
1592
1584
|
ws(handler) {
|
|
1593
1585
|
this.wsHandler = handler;
|
|
1594
1586
|
}
|
|
1595
|
-
server;
|
|
1596
1587
|
async listen(port, hostname, backlog, listeningListener) {
|
|
1597
1588
|
const server = this.server = http.default.createServer(this.getServerCb());
|
|
1598
1589
|
if (this.wsHandler) {
|
|
@@ -1677,19 +1668,19 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1677
1668
|
return (req, res) => {
|
|
1678
1669
|
const response = new this.ResponseClass(res, req, ctxOptions.logger, defaultHeaders);
|
|
1679
1670
|
const method = req.method || "";
|
|
1680
|
-
const url
|
|
1671
|
+
const url = req.url || "";
|
|
1681
1672
|
createHttpContext(ctxOptions, {
|
|
1682
1673
|
req,
|
|
1683
1674
|
response,
|
|
1684
1675
|
requestLimits: RequestLimits
|
|
1685
1676
|
}, () => {
|
|
1686
|
-
const ctx = (0,
|
|
1687
|
-
const handlers = this.wooks.lookupHandlers(method, url
|
|
1677
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
1678
|
+
const handlers = this.wooks.lookupHandlers(method, url, ctx);
|
|
1688
1679
|
if (handlers) return this.processAndCatch(handlers, ctx, response);
|
|
1689
1680
|
else if (onNoMatch) onNoMatch(req, res);
|
|
1690
1681
|
else if (notFoundHandler) return this.processAndCatch([notFoundHandler], ctx, response);
|
|
1691
1682
|
else {
|
|
1692
|
-
this.logger.debug(`404 Not found (${method})${url
|
|
1683
|
+
this.logger.debug(`404 Not found (${method})${url}`);
|
|
1693
1684
|
const error = new HttpError(404);
|
|
1694
1685
|
this.respond(error, response, ctx);
|
|
1695
1686
|
return error;
|
|
@@ -1710,17 +1701,17 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1710
1701
|
socket.destroy();
|
|
1711
1702
|
return;
|
|
1712
1703
|
}
|
|
1713
|
-
const url
|
|
1704
|
+
const url = req.url || "";
|
|
1714
1705
|
createHttpContext(ctxOptions, {
|
|
1715
1706
|
req,
|
|
1716
1707
|
response: void 0,
|
|
1717
1708
|
requestLimits
|
|
1718
1709
|
}, () => {
|
|
1719
|
-
const ctx = (0,
|
|
1710
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
1720
1711
|
ctx.set(wsHandler.reqKey, req);
|
|
1721
1712
|
ctx.set(wsHandler.socketKey, socket);
|
|
1722
1713
|
ctx.set(wsHandler.headKey, head);
|
|
1723
|
-
const handlers = this.wooks.lookupHandlers("UPGRADE", url
|
|
1714
|
+
const handlers = this.wooks.lookupHandlers("UPGRADE", url, ctx);
|
|
1724
1715
|
if (handlers) return this.processUpgradeHandlers(handlers, ctx, socket);
|
|
1725
1716
|
else return wsHandler.handleUpgrade(req, socket, head);
|
|
1726
1717
|
});
|
|
@@ -1818,10 +1809,10 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1818
1809
|
* @returns A Web Standard Response, or `null` if no route matched (and no `onNotFound` handler is set).
|
|
1819
1810
|
*/
|
|
1820
1811
|
async fetch(request) {
|
|
1821
|
-
const url
|
|
1812
|
+
const url = new URL(request.url);
|
|
1822
1813
|
const method = request.method;
|
|
1823
|
-
const pathname = url
|
|
1824
|
-
const callerCtx = (0,
|
|
1814
|
+
const pathname = url.pathname + url.search;
|
|
1815
|
+
const callerCtx = (0, _wooksjs_event_core.tryGetCurrent)();
|
|
1825
1816
|
let callerReq;
|
|
1826
1817
|
if (callerCtx) try {
|
|
1827
1818
|
callerReq = callerCtx.get(httpKind.keys.req);
|
|
@@ -1831,23 +1822,23 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1831
1822
|
let rawChunks;
|
|
1832
1823
|
let rawHeaders;
|
|
1833
1824
|
let rawStatusCode = 0;
|
|
1834
|
-
fakeRes.writeHead = (...args) => {
|
|
1825
|
+
fakeRes.writeHead = ((...args) => {
|
|
1835
1826
|
rawStatusCode = args[0];
|
|
1836
1827
|
for (const arg of args) if (typeof arg === "object" && arg !== null) {
|
|
1837
1828
|
if (!rawHeaders) rawHeaders = {};
|
|
1838
1829
|
for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
|
|
1839
1830
|
}
|
|
1840
1831
|
return fakeRes;
|
|
1841
|
-
};
|
|
1842
|
-
fakeRes.write = (chunk, _encoding, cb) => {
|
|
1832
|
+
});
|
|
1833
|
+
fakeRes.write = ((chunk, _encoding, cb) => {
|
|
1843
1834
|
if (chunk !== null && chunk !== void 0) {
|
|
1844
1835
|
if (!rawChunks) rawChunks = [];
|
|
1845
1836
|
rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
|
|
1846
1837
|
}
|
|
1847
1838
|
if (typeof cb === "function") cb();
|
|
1848
1839
|
return true;
|
|
1849
|
-
};
|
|
1850
|
-
fakeRes.end = (chunk, _encoding, cb) => {
|
|
1840
|
+
});
|
|
1841
|
+
fakeRes.end = ((chunk, _encoding, cb) => {
|
|
1851
1842
|
if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") {
|
|
1852
1843
|
if (!rawChunks) rawChunks = [];
|
|
1853
1844
|
rawChunks.push(typeof chunk === "string" ? buffer.Buffer.from(chunk) : chunk);
|
|
@@ -1855,7 +1846,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1855
1846
|
if (typeof chunk === "function") chunk();
|
|
1856
1847
|
else if (typeof cb === "function") cb();
|
|
1857
1848
|
return fakeRes;
|
|
1858
|
-
};
|
|
1849
|
+
});
|
|
1859
1850
|
const response = new this.ResponseClass(fakeRes, fakeReq, this.logger, this.opts?.defaultHeaders, true);
|
|
1860
1851
|
let bodyBuffer;
|
|
1861
1852
|
if (request.body) bodyBuffer = buffer.Buffer.from(await request.bytes());
|
|
@@ -1866,7 +1857,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1866
1857
|
response,
|
|
1867
1858
|
requestLimits
|
|
1868
1859
|
}, async () => {
|
|
1869
|
-
const ctx = (0,
|
|
1860
|
+
const ctx = (0, _wooksjs_event_core.current)();
|
|
1870
1861
|
if (bodyBuffer) ctx.set(rawBodySlot, Promise.resolve(bodyBuffer));
|
|
1871
1862
|
try {
|
|
1872
1863
|
const handlers = this.wooks.lookupHandlers(method, pathname, ctx);
|
|
@@ -1913,7 +1904,10 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1913
1904
|
}
|
|
1914
1905
|
};
|
|
1915
1906
|
var NoopSocket = class extends stream.Duplex {
|
|
1916
|
-
|
|
1907
|
+
constructor(..._args) {
|
|
1908
|
+
super(..._args);
|
|
1909
|
+
this.remoteAddress = "127.0.0.1";
|
|
1910
|
+
}
|
|
1917
1911
|
_read() {}
|
|
1918
1912
|
_write(_chunk, _enc, cb) {
|
|
1919
1913
|
cb();
|
|
@@ -1945,8 +1939,8 @@ function createFakeIncomingMessage(request, pathname, forwardFrom, forwardHeader
|
|
|
1945
1939
|
* app.listen(3000)
|
|
1946
1940
|
* ```
|
|
1947
1941
|
*/
|
|
1948
|
-
function createHttpApp(opts, wooks$
|
|
1949
|
-
return new WooksHttp(opts, wooks$
|
|
1942
|
+
function createHttpApp(opts, wooks$2) {
|
|
1943
|
+
return new WooksHttp(opts, wooks$2);
|
|
1950
1944
|
}
|
|
1951
1945
|
|
|
1952
1946
|
//#endregion
|
|
@@ -2029,20 +2023,19 @@ function prepareTestHttpContext(options) {
|
|
|
2029
2023
|
req.method = options.method || "GET";
|
|
2030
2024
|
req.headers = options.headers || {};
|
|
2031
2025
|
req.url = options.url;
|
|
2032
|
-
const
|
|
2033
|
-
const
|
|
2034
|
-
const ctx = new __wooksjs_event_core.EventContext({ logger: console });
|
|
2026
|
+
const response = new HttpResponse(new http.ServerResponse(req), req, console, options.defaultHeaders);
|
|
2027
|
+
const ctx = new _wooksjs_event_core.EventContext({ logger: console });
|
|
2035
2028
|
ctx.seed(httpKind, {
|
|
2036
2029
|
req,
|
|
2037
2030
|
response,
|
|
2038
2031
|
requestLimits: options.requestLimits
|
|
2039
2032
|
});
|
|
2040
|
-
if (options.params) ctx.set(
|
|
2033
|
+
if (options.params) ctx.set(_wooksjs_event_core.routeParamsKey, options.params);
|
|
2041
2034
|
if (options.rawBody !== void 0) {
|
|
2042
2035
|
const buf = buffer.Buffer.isBuffer(options.rawBody) ? options.rawBody : buffer.Buffer.from(options.rawBody);
|
|
2043
2036
|
ctx.set(rawBodySlot, Promise.resolve(buf));
|
|
2044
2037
|
}
|
|
2045
|
-
return (cb) => (0,
|
|
2038
|
+
return (cb) => (0, _wooksjs_event_core.run)(ctx, cb);
|
|
2046
2039
|
}
|
|
2047
2040
|
|
|
2048
2041
|
//#endregion
|
|
@@ -2070,7 +2063,7 @@ exports.useHttpContext = useHttpContext;
|
|
|
2070
2063
|
Object.defineProperty(exports, 'useLogger', {
|
|
2071
2064
|
enumerable: true,
|
|
2072
2065
|
get: function () {
|
|
2073
|
-
return
|
|
2066
|
+
return _wooksjs_event_core.useLogger;
|
|
2074
2067
|
}
|
|
2075
2068
|
});
|
|
2076
2069
|
exports.useRequest = useRequest;
|
|
@@ -2078,7 +2071,7 @@ exports.useResponse = useResponse;
|
|
|
2078
2071
|
Object.defineProperty(exports, 'useRouteParams', {
|
|
2079
2072
|
enumerable: true,
|
|
2080
2073
|
get: function () {
|
|
2081
|
-
return
|
|
2074
|
+
return _wooksjs_event_core.useRouteParams;
|
|
2082
2075
|
}
|
|
2083
2076
|
});
|
|
2084
2077
|
exports.useUrlParams = useUrlParams;
|
package/dist/index.mjs
CHANGED
|
@@ -81,9 +81,8 @@ const acceptsMime = cachedBy((type, ctx) => {
|
|
|
81
81
|
});
|
|
82
82
|
/** Provides helpers to check the request's Accept header for supported MIME types. */
|
|
83
83
|
const useAccept = defineWook((ctx) => {
|
|
84
|
-
const accept = ctx.get(httpKind.keys.req).headers.accept;
|
|
85
84
|
return {
|
|
86
|
-
accept,
|
|
85
|
+
accept: ctx.get(httpKind.keys.req).headers.accept,
|
|
87
86
|
has: (type) => acceptsMime(type, ctx)
|
|
88
87
|
};
|
|
89
88
|
});
|
|
@@ -107,12 +106,9 @@ const authCredentialsSlot = cached((ctx) => {
|
|
|
107
106
|
return null;
|
|
108
107
|
});
|
|
109
108
|
const basicCredentialsSlot = cached((ctx) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (type?.toLocaleLowerCase() === "basic") {
|
|
114
|
-
const creds = Buffer$1.from(ctx.get(authCredentialsSlot) || "", "base64").toString("ascii");
|
|
115
|
-
const [username, password] = creds.split(":");
|
|
109
|
+
if (ctx.get(httpKind.keys.req).headers.authorization) {
|
|
110
|
+
if (ctx.get(authTypeSlot)?.toLocaleLowerCase() === "basic") {
|
|
111
|
+
const [username, password] = Buffer$1.from(ctx.get(authCredentialsSlot) || "", "base64").toString("ascii").split(":");
|
|
116
112
|
return {
|
|
117
113
|
username,
|
|
118
114
|
password
|
|
@@ -122,8 +118,7 @@ const basicCredentialsSlot = cached((ctx) => {
|
|
|
122
118
|
return null;
|
|
123
119
|
});
|
|
124
120
|
const authIsSlot = cachedBy((type, ctx) => {
|
|
125
|
-
|
|
126
|
-
return authType?.toLowerCase() === type.toLowerCase();
|
|
121
|
+
return ctx.get(authTypeSlot)?.toLowerCase() === type.toLowerCase();
|
|
127
122
|
});
|
|
128
123
|
/**
|
|
129
124
|
* Provides parsed access to the Authorization header (type, credentials, Basic decoding).
|
|
@@ -134,9 +129,8 @@ const authIsSlot = cachedBy((type, ctx) => {
|
|
|
134
129
|
* ```
|
|
135
130
|
*/
|
|
136
131
|
const useAuthorization = defineWook((ctx) => {
|
|
137
|
-
const authorization = ctx.get(httpKind.keys.req).headers.authorization;
|
|
138
132
|
return {
|
|
139
|
-
authorization,
|
|
133
|
+
authorization: ctx.get(httpKind.keys.req).headers.authorization,
|
|
140
134
|
type: () => ctx.get(authTypeSlot),
|
|
141
135
|
credentials: () => ctx.get(authCredentialsSlot),
|
|
142
136
|
is: (type) => authIsSlot(type, ctx),
|
|
@@ -289,84 +283,84 @@ const httpStatusCodes = {
|
|
|
289
283
|
511: "Network Authentication Required"
|
|
290
284
|
};
|
|
291
285
|
/** Enum of all standard HTTP status codes (100–511). */
|
|
292
|
-
let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode
|
|
293
|
-
EHttpStatusCode
|
|
294
|
-
EHttpStatusCode
|
|
295
|
-
EHttpStatusCode
|
|
296
|
-
EHttpStatusCode
|
|
297
|
-
EHttpStatusCode
|
|
298
|
-
EHttpStatusCode
|
|
299
|
-
EHttpStatusCode
|
|
300
|
-
EHttpStatusCode
|
|
301
|
-
EHttpStatusCode
|
|
302
|
-
EHttpStatusCode
|
|
303
|
-
EHttpStatusCode
|
|
304
|
-
EHttpStatusCode
|
|
305
|
-
EHttpStatusCode
|
|
306
|
-
EHttpStatusCode
|
|
307
|
-
EHttpStatusCode
|
|
308
|
-
EHttpStatusCode
|
|
309
|
-
EHttpStatusCode
|
|
310
|
-
EHttpStatusCode
|
|
311
|
-
EHttpStatusCode
|
|
312
|
-
EHttpStatusCode
|
|
313
|
-
EHttpStatusCode
|
|
314
|
-
EHttpStatusCode
|
|
315
|
-
EHttpStatusCode
|
|
316
|
-
EHttpStatusCode
|
|
317
|
-
EHttpStatusCode
|
|
318
|
-
EHttpStatusCode
|
|
319
|
-
EHttpStatusCode
|
|
320
|
-
EHttpStatusCode
|
|
321
|
-
EHttpStatusCode
|
|
322
|
-
EHttpStatusCode
|
|
323
|
-
EHttpStatusCode
|
|
324
|
-
EHttpStatusCode
|
|
325
|
-
EHttpStatusCode
|
|
326
|
-
EHttpStatusCode
|
|
327
|
-
EHttpStatusCode
|
|
328
|
-
EHttpStatusCode
|
|
329
|
-
EHttpStatusCode
|
|
330
|
-
EHttpStatusCode
|
|
331
|
-
EHttpStatusCode
|
|
332
|
-
EHttpStatusCode
|
|
333
|
-
EHttpStatusCode
|
|
334
|
-
EHttpStatusCode
|
|
335
|
-
EHttpStatusCode
|
|
336
|
-
EHttpStatusCode
|
|
337
|
-
EHttpStatusCode
|
|
338
|
-
EHttpStatusCode
|
|
339
|
-
EHttpStatusCode
|
|
340
|
-
EHttpStatusCode
|
|
341
|
-
EHttpStatusCode
|
|
342
|
-
EHttpStatusCode
|
|
343
|
-
EHttpStatusCode
|
|
344
|
-
EHttpStatusCode
|
|
345
|
-
EHttpStatusCode
|
|
346
|
-
EHttpStatusCode
|
|
347
|
-
EHttpStatusCode
|
|
348
|
-
EHttpStatusCode
|
|
349
|
-
EHttpStatusCode
|
|
350
|
-
EHttpStatusCode
|
|
351
|
-
EHttpStatusCode
|
|
352
|
-
EHttpStatusCode
|
|
353
|
-
EHttpStatusCode
|
|
354
|
-
EHttpStatusCode
|
|
355
|
-
EHttpStatusCode
|
|
356
|
-
return EHttpStatusCode
|
|
286
|
+
let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode) {
|
|
287
|
+
EHttpStatusCode[EHttpStatusCode["Continue"] = 100] = "Continue";
|
|
288
|
+
EHttpStatusCode[EHttpStatusCode["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
289
|
+
EHttpStatusCode[EHttpStatusCode["Processing"] = 102] = "Processing";
|
|
290
|
+
EHttpStatusCode[EHttpStatusCode["EarlyHints"] = 103] = "EarlyHints";
|
|
291
|
+
EHttpStatusCode[EHttpStatusCode["OK"] = 200] = "OK";
|
|
292
|
+
EHttpStatusCode[EHttpStatusCode["Created"] = 201] = "Created";
|
|
293
|
+
EHttpStatusCode[EHttpStatusCode["Accepted"] = 202] = "Accepted";
|
|
294
|
+
EHttpStatusCode[EHttpStatusCode["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
295
|
+
EHttpStatusCode[EHttpStatusCode["NoContent"] = 204] = "NoContent";
|
|
296
|
+
EHttpStatusCode[EHttpStatusCode["ResetContent"] = 205] = "ResetContent";
|
|
297
|
+
EHttpStatusCode[EHttpStatusCode["PartialContent"] = 206] = "PartialContent";
|
|
298
|
+
EHttpStatusCode[EHttpStatusCode["MultiStatus"] = 207] = "MultiStatus";
|
|
299
|
+
EHttpStatusCode[EHttpStatusCode["AlreadyReported"] = 208] = "AlreadyReported";
|
|
300
|
+
EHttpStatusCode[EHttpStatusCode["IMUsed"] = 226] = "IMUsed";
|
|
301
|
+
EHttpStatusCode[EHttpStatusCode["MultipleChoices"] = 300] = "MultipleChoices";
|
|
302
|
+
EHttpStatusCode[EHttpStatusCode["MovedPermanently"] = 301] = "MovedPermanently";
|
|
303
|
+
EHttpStatusCode[EHttpStatusCode["Found"] = 302] = "Found";
|
|
304
|
+
EHttpStatusCode[EHttpStatusCode["SeeOther"] = 303] = "SeeOther";
|
|
305
|
+
EHttpStatusCode[EHttpStatusCode["NotModified"] = 304] = "NotModified";
|
|
306
|
+
EHttpStatusCode[EHttpStatusCode["UseProxy"] = 305] = "UseProxy";
|
|
307
|
+
EHttpStatusCode[EHttpStatusCode["SwitchProxy"] = 306] = "SwitchProxy";
|
|
308
|
+
EHttpStatusCode[EHttpStatusCode["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
309
|
+
EHttpStatusCode[EHttpStatusCode["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
310
|
+
EHttpStatusCode[EHttpStatusCode["BadRequest"] = 400] = "BadRequest";
|
|
311
|
+
EHttpStatusCode[EHttpStatusCode["Unauthorized"] = 401] = "Unauthorized";
|
|
312
|
+
EHttpStatusCode[EHttpStatusCode["PaymentRequired"] = 402] = "PaymentRequired";
|
|
313
|
+
EHttpStatusCode[EHttpStatusCode["Forbidden"] = 403] = "Forbidden";
|
|
314
|
+
EHttpStatusCode[EHttpStatusCode["NotFound"] = 404] = "NotFound";
|
|
315
|
+
EHttpStatusCode[EHttpStatusCode["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
316
|
+
EHttpStatusCode[EHttpStatusCode["NotAcceptable"] = 406] = "NotAcceptable";
|
|
317
|
+
EHttpStatusCode[EHttpStatusCode["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
318
|
+
EHttpStatusCode[EHttpStatusCode["RequestTimeout"] = 408] = "RequestTimeout";
|
|
319
|
+
EHttpStatusCode[EHttpStatusCode["Conflict"] = 409] = "Conflict";
|
|
320
|
+
EHttpStatusCode[EHttpStatusCode["Gone"] = 410] = "Gone";
|
|
321
|
+
EHttpStatusCode[EHttpStatusCode["LengthRequired"] = 411] = "LengthRequired";
|
|
322
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
323
|
+
EHttpStatusCode[EHttpStatusCode["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
324
|
+
EHttpStatusCode[EHttpStatusCode["URITooLong"] = 414] = "URITooLong";
|
|
325
|
+
EHttpStatusCode[EHttpStatusCode["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
326
|
+
EHttpStatusCode[EHttpStatusCode["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
327
|
+
EHttpStatusCode[EHttpStatusCode["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
328
|
+
EHttpStatusCode[EHttpStatusCode["ImATeapot"] = 418] = "ImATeapot";
|
|
329
|
+
EHttpStatusCode[EHttpStatusCode["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
330
|
+
EHttpStatusCode[EHttpStatusCode["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
331
|
+
EHttpStatusCode[EHttpStatusCode["Locked"] = 423] = "Locked";
|
|
332
|
+
EHttpStatusCode[EHttpStatusCode["FailedDependency"] = 424] = "FailedDependency";
|
|
333
|
+
EHttpStatusCode[EHttpStatusCode["TooEarly"] = 425] = "TooEarly";
|
|
334
|
+
EHttpStatusCode[EHttpStatusCode["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
335
|
+
EHttpStatusCode[EHttpStatusCode["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
336
|
+
EHttpStatusCode[EHttpStatusCode["TooManyRequests"] = 429] = "TooManyRequests";
|
|
337
|
+
EHttpStatusCode[EHttpStatusCode["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
338
|
+
EHttpStatusCode[EHttpStatusCode["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
339
|
+
EHttpStatusCode[EHttpStatusCode["InternalServerError"] = 500] = "InternalServerError";
|
|
340
|
+
EHttpStatusCode[EHttpStatusCode["NotImplemented"] = 501] = "NotImplemented";
|
|
341
|
+
EHttpStatusCode[EHttpStatusCode["BadGateway"] = 502] = "BadGateway";
|
|
342
|
+
EHttpStatusCode[EHttpStatusCode["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
343
|
+
EHttpStatusCode[EHttpStatusCode["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
344
|
+
EHttpStatusCode[EHttpStatusCode["HTTPVersionNotSupported"] = 505] = "HTTPVersionNotSupported";
|
|
345
|
+
EHttpStatusCode[EHttpStatusCode["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
346
|
+
EHttpStatusCode[EHttpStatusCode["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
347
|
+
EHttpStatusCode[EHttpStatusCode["LoopDetected"] = 508] = "LoopDetected";
|
|
348
|
+
EHttpStatusCode[EHttpStatusCode["NotExtended"] = 510] = "NotExtended";
|
|
349
|
+
EHttpStatusCode[EHttpStatusCode["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
350
|
+
return EHttpStatusCode;
|
|
357
351
|
}({});
|
|
358
352
|
|
|
359
353
|
//#endregion
|
|
360
354
|
//#region packages/event-http/src/errors/http-error.ts
|
|
361
355
|
/** Represents an HTTP error with a status code and optional structured body. */
|
|
362
356
|
var HttpError = class extends Error {
|
|
363
|
-
name = "HttpError";
|
|
364
357
|
constructor(code = 500, _body = "") {
|
|
365
358
|
const prev = Error.stackTraceLimit;
|
|
366
359
|
Error.stackTraceLimit = 0;
|
|
367
360
|
super(typeof _body === "string" ? _body : _body.message);
|
|
368
361
|
this.code = code;
|
|
369
362
|
this._body = _body;
|
|
363
|
+
this.name = "HttpError";
|
|
370
364
|
Error.stackTraceLimit = prev;
|
|
371
365
|
}
|
|
372
366
|
get body() {
|
|
@@ -394,9 +388,7 @@ const DEFAULT_LIMITS = {
|
|
|
394
388
|
readTimeoutMs: 1e4
|
|
395
389
|
};
|
|
396
390
|
const contentEncodingsSlot = cached((ctx) => {
|
|
397
|
-
|
|
398
|
-
const contentEncoding = req.headers["content-encoding"];
|
|
399
|
-
return (contentEncoding || "").split(",").map((p) => p.trim()).filter((p) => !!p);
|
|
391
|
+
return (ctx.get(httpKind.keys.req).headers["content-encoding"] || "").split(",").map((p) => p.trim()).filter((p) => !!p);
|
|
400
392
|
});
|
|
401
393
|
const isCompressedSlot = cached((ctx) => {
|
|
402
394
|
const parts = ctx.get(contentEncodingsSlot);
|
|
@@ -597,10 +589,8 @@ var WooksURLSearchParams = class extends URLSearchParams {
|
|
|
597
589
|
/** Converts query parameters to a plain object. Array params (keys ending with `[]`) become `string[]`. */
|
|
598
590
|
toJson() {
|
|
599
591
|
const json = Object.create(null);
|
|
600
|
-
for (const [key, value] of this.entries()) if (isArrayParam(key))
|
|
601
|
-
|
|
602
|
-
a.push(value);
|
|
603
|
-
} else {
|
|
592
|
+
for (const [key, value] of this.entries()) if (isArrayParam(key)) (json[key] = json[key] || []).push(value);
|
|
593
|
+
else {
|
|
604
594
|
if (ILLEGAL_KEYS.has(key)) throw new HttpError(400, `Illegal key name "${key}"`);
|
|
605
595
|
if (key in json) throw new HttpError(400, `Duplicate key "${key}"`);
|
|
606
596
|
json[key] = value;
|
|
@@ -712,10 +702,10 @@ function renderCookie(key, data) {
|
|
|
712
702
|
return `${key}=${encodeURIComponent(data.value)}${attrs}`;
|
|
713
703
|
}
|
|
714
704
|
const cookieAttrFunc = {
|
|
715
|
-
expires: (v) => `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
|
|
716
|
-
maxAge: (v) => `Max-Age=${convertTime(v, "s").toString()}`,
|
|
717
|
-
domain: (v) => `Domain=${sanitizeCookieAttrValue(String(v))}`,
|
|
718
|
-
path: (v) => `Path=${sanitizeCookieAttrValue(String(v))}`,
|
|
705
|
+
expires: (v) => v === void 0 ? "" : `Expires=${typeof v === "string" || typeof v === "number" ? new Date(v).toUTCString() : v.toUTCString()}`,
|
|
706
|
+
maxAge: (v) => v === void 0 ? "" : `Max-Age=${convertTime(v, "s").toString()}`,
|
|
707
|
+
domain: (v) => v === void 0 ? "" : `Domain=${sanitizeCookieAttrValue(String(v))}`,
|
|
708
|
+
path: (v) => v === void 0 ? "" : `Path=${sanitizeCookieAttrValue(String(v))}`,
|
|
719
709
|
secure: (v) => v ? "Secure" : "",
|
|
720
710
|
httpOnly: (v) => v ? "HttpOnly" : "",
|
|
721
711
|
sameSite: (v) => v ? `SameSite=${typeof v === "string" ? v : "Strict"}` : ""
|
|
@@ -756,15 +746,15 @@ var HttpResponse = class {
|
|
|
756
746
|
this._req = _req;
|
|
757
747
|
this._logger = _logger;
|
|
758
748
|
this._captureMode = _captureMode;
|
|
749
|
+
this._status = 0;
|
|
750
|
+
this._body = void 0;
|
|
751
|
+
this._headers = {};
|
|
752
|
+
this._cookies = {};
|
|
753
|
+
this._rawCookies = [];
|
|
754
|
+
this._hasCookies = false;
|
|
755
|
+
this._responded = false;
|
|
759
756
|
if (defaultHeaders) for (const key in defaultHeaders) this._headers[key] = defaultHeaders[key];
|
|
760
757
|
}
|
|
761
|
-
_status = 0;
|
|
762
|
-
_body = void 0;
|
|
763
|
-
_headers = {};
|
|
764
|
-
_cookies = {};
|
|
765
|
-
_rawCookies = [];
|
|
766
|
-
_hasCookies = false;
|
|
767
|
-
_responded = false;
|
|
768
758
|
/** The HTTP status code. If not set, it is inferred automatically when `send()` is called. */
|
|
769
759
|
get status() {
|
|
770
760
|
return this._status;
|
|
@@ -1438,7 +1428,7 @@ function escapeHtml(value) {
|
|
|
1438
1428
|
//#endregion
|
|
1439
1429
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1440
1430
|
let framework = {
|
|
1441
|
-
version: "0.7.
|
|
1431
|
+
version: "0.7.12",
|
|
1442
1432
|
poweredBy: "wooksjs",
|
|
1443
1433
|
link: "https://wooks.moost.org/",
|
|
1444
1434
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
|
@@ -1518,9 +1508,6 @@ const DEFAULT_FORWARD_HEADERS = [
|
|
|
1518
1508
|
];
|
|
1519
1509
|
/** HTTP adapter for Wooks that provides route registration, server lifecycle, and request handling. */
|
|
1520
1510
|
var WooksHttp = class extends WooksAdapterBase {
|
|
1521
|
-
logger;
|
|
1522
|
-
ResponseClass;
|
|
1523
|
-
eventContextOptions;
|
|
1524
1511
|
constructor(opts, wooks) {
|
|
1525
1512
|
super(wooks, opts?.logger, opts?.router);
|
|
1526
1513
|
this.opts = opts;
|
|
@@ -1564,12 +1551,10 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1564
1551
|
upgrade(path, handler) {
|
|
1565
1552
|
return this.on("UPGRADE", path, handler);
|
|
1566
1553
|
}
|
|
1567
|
-
wsHandler;
|
|
1568
1554
|
/** Register a WebSocket upgrade handler that implements the WooksUpgradeHandler contract. */
|
|
1569
1555
|
ws(handler) {
|
|
1570
1556
|
this.wsHandler = handler;
|
|
1571
1557
|
}
|
|
1572
|
-
server;
|
|
1573
1558
|
async listen(port, hostname, backlog, listeningListener) {
|
|
1574
1559
|
const server = this.server = http.createServer(this.getServerCb());
|
|
1575
1560
|
if (this.wsHandler) {
|
|
@@ -1808,23 +1793,23 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1808
1793
|
let rawChunks;
|
|
1809
1794
|
let rawHeaders;
|
|
1810
1795
|
let rawStatusCode = 0;
|
|
1811
|
-
fakeRes.writeHead = (...args) => {
|
|
1796
|
+
fakeRes.writeHead = ((...args) => {
|
|
1812
1797
|
rawStatusCode = args[0];
|
|
1813
1798
|
for (const arg of args) if (typeof arg === "object" && arg !== null) {
|
|
1814
1799
|
if (!rawHeaders) rawHeaders = {};
|
|
1815
1800
|
for (const [k, v] of Object.entries(arg)) rawHeaders[k] = v;
|
|
1816
1801
|
}
|
|
1817
1802
|
return fakeRes;
|
|
1818
|
-
};
|
|
1819
|
-
fakeRes.write = (chunk, _encoding, cb) => {
|
|
1803
|
+
});
|
|
1804
|
+
fakeRes.write = ((chunk, _encoding, cb) => {
|
|
1820
1805
|
if (chunk !== null && chunk !== void 0) {
|
|
1821
1806
|
if (!rawChunks) rawChunks = [];
|
|
1822
1807
|
rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
|
|
1823
1808
|
}
|
|
1824
1809
|
if (typeof cb === "function") cb();
|
|
1825
1810
|
return true;
|
|
1826
|
-
};
|
|
1827
|
-
fakeRes.end = (chunk, _encoding, cb) => {
|
|
1811
|
+
});
|
|
1812
|
+
fakeRes.end = ((chunk, _encoding, cb) => {
|
|
1828
1813
|
if (chunk !== null && chunk !== void 0 && typeof chunk !== "function") {
|
|
1829
1814
|
if (!rawChunks) rawChunks = [];
|
|
1830
1815
|
rawChunks.push(typeof chunk === "string" ? Buffer$1.from(chunk) : chunk);
|
|
@@ -1832,7 +1817,7 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1832
1817
|
if (typeof chunk === "function") chunk();
|
|
1833
1818
|
else if (typeof cb === "function") cb();
|
|
1834
1819
|
return fakeRes;
|
|
1835
|
-
};
|
|
1820
|
+
});
|
|
1836
1821
|
const response = new this.ResponseClass(fakeRes, fakeReq, this.logger, this.opts?.defaultHeaders, true);
|
|
1837
1822
|
let bodyBuffer;
|
|
1838
1823
|
if (request.body) bodyBuffer = Buffer$1.from(await request.bytes());
|
|
@@ -1890,7 +1875,10 @@ var WooksHttp = class extends WooksAdapterBase {
|
|
|
1890
1875
|
}
|
|
1891
1876
|
};
|
|
1892
1877
|
var NoopSocket = class extends Duplex {
|
|
1893
|
-
|
|
1878
|
+
constructor(..._args) {
|
|
1879
|
+
super(..._args);
|
|
1880
|
+
this.remoteAddress = "127.0.0.1";
|
|
1881
|
+
}
|
|
1894
1882
|
_read() {}
|
|
1895
1883
|
_write(_chunk, _enc, cb) {
|
|
1896
1884
|
cb();
|
|
@@ -2006,8 +1994,7 @@ function prepareTestHttpContext(options) {
|
|
|
2006
1994
|
req.method = options.method || "GET";
|
|
2007
1995
|
req.headers = options.headers || {};
|
|
2008
1996
|
req.url = options.url;
|
|
2009
|
-
const
|
|
2010
|
-
const response = new HttpResponse(res, req, console, options.defaultHeaders);
|
|
1997
|
+
const response = new HttpResponse(new ServerResponse(req), req, console, options.defaultHeaders);
|
|
2011
1998
|
const ctx = new EventContext({ logger: console });
|
|
2012
1999
|
ctx.seed(httpKind, {
|
|
2013
2000
|
req,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^3.2.4",
|
|
45
|
-
"@wooksjs/event-core": "^0.7.
|
|
46
|
-
"wooks": "^0.7.
|
|
45
|
+
"@wooksjs/event-core": "^0.7.13",
|
|
46
|
+
"wooks": "^0.7.13"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@prostojs/logger": "^0.4.3",
|
|
50
|
-
"@prostojs/router": "^0.3.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"@prostojs/router": "^0.3.4",
|
|
51
|
+
"wooks": "^0.7.13",
|
|
52
|
+
"@wooksjs/event-core": "^0.7.13"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "rolldown -c ../../rolldown.config.mjs"
|