@wooksjs/event-http 0.7.20 → 0.7.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -8
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +18 -8
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -942,9 +942,7 @@ var HttpResponse = class {
|
|
|
942
942
|
}
|
|
943
943
|
if (hasFetchResponse && body instanceof globalThis.Response) {
|
|
944
944
|
this._status = this._status || body.status;
|
|
945
|
-
|
|
946
|
-
if (!this._headers[k]) this._headers[k] = v;
|
|
947
|
-
});
|
|
945
|
+
this.mergeFetchResponseHeaders(body);
|
|
948
946
|
return new globalThis.Response(method === "HEAD" ? null : body.body, {
|
|
949
947
|
status: this._status,
|
|
950
948
|
headers: this._buildWebHeaders()
|
|
@@ -971,6 +969,21 @@ var HttpResponse = class {
|
|
|
971
969
|
_buildWebHeaders() {
|
|
972
970
|
return recordToWebHeaders(this._headers);
|
|
973
971
|
}
|
|
972
|
+
/**
|
|
973
|
+
* Merges headers from a handler-returned fetch `Response` into the buffered headers.
|
|
974
|
+
* Explicitly buffered headers win. `set-cookie` is appended in array form so multiple
|
|
975
|
+
* cookies survive (`Headers` iteration would otherwise keep only the first).
|
|
976
|
+
*/
|
|
977
|
+
mergeFetchResponseHeaders(fetchResponse) {
|
|
978
|
+
fetchResponse.headers.forEach((value, key) => {
|
|
979
|
+
if (key !== "set-cookie" && !this._headers[key]) this._headers[key] = value;
|
|
980
|
+
});
|
|
981
|
+
const setCookies = typeof fetchResponse.headers.getSetCookie === "function" ? fetchResponse.headers.getSetCookie() : [];
|
|
982
|
+
if (setCookies.length > 0) {
|
|
983
|
+
const existing = this._headers["set-cookie"];
|
|
984
|
+
this._headers["set-cookie"] = existing ? [...Array.isArray(existing) ? existing : [existing], ...setCookies] : setCookies;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
974
987
|
renderBody() {
|
|
975
988
|
const body = this._body;
|
|
976
989
|
if (body === void 0 || body === null) return "";
|
|
@@ -1071,10 +1084,7 @@ var HttpResponse = class {
|
|
|
1071
1084
|
}
|
|
1072
1085
|
async sendFetchResponse(fetchResponse, method) {
|
|
1073
1086
|
this._status = this._status || fetchResponse.status;
|
|
1074
|
-
|
|
1075
|
-
if (fetchContentLength) this._headers["content-length"] = fetchContentLength;
|
|
1076
|
-
const fetchContentType = fetchResponse.headers.get("content-type");
|
|
1077
|
-
if (fetchContentType) this._headers["content-type"] = fetchContentType;
|
|
1087
|
+
this.mergeFetchResponseHeaders(fetchResponse);
|
|
1078
1088
|
this._res.writeHead(this._status, this._headers);
|
|
1079
1089
|
if (method === "HEAD") {
|
|
1080
1090
|
this._res.end();
|
|
@@ -1469,7 +1479,7 @@ function escapeHtml(value) {
|
|
|
1469
1479
|
//#endregion
|
|
1470
1480
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1471
1481
|
let framework = {
|
|
1472
|
-
version: "0.7.
|
|
1482
|
+
version: "0.7.20",
|
|
1473
1483
|
poweredBy: "wooksjs",
|
|
1474
1484
|
link: "https://wooks.moost.org/",
|
|
1475
1485
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
package/dist/index.d.ts
CHANGED
|
@@ -428,6 +428,12 @@ declare class HttpResponse {
|
|
|
428
428
|
*/
|
|
429
429
|
toWebResponse(): Response;
|
|
430
430
|
private _buildWebHeaders;
|
|
431
|
+
/**
|
|
432
|
+
* Merges headers from a handler-returned fetch `Response` into the buffered headers.
|
|
433
|
+
* Explicitly buffered headers win. `set-cookie` is appended in array form so multiple
|
|
434
|
+
* cookies survive (`Headers` iteration would otherwise keep only the first).
|
|
435
|
+
*/
|
|
436
|
+
protected mergeFetchResponseHeaders(fetchResponse: Response): void;
|
|
431
437
|
protected renderBody(): string | Uint8Array;
|
|
432
438
|
protected renderError(data: TWooksErrorBodyExt, _ctx: EventContext): void;
|
|
433
439
|
/** Renders and sends an HTTP error response. Called automatically by the framework when a handler throws an `HttpError`. */
|
package/dist/index.mjs
CHANGED
|
@@ -913,9 +913,7 @@ var HttpResponse = class {
|
|
|
913
913
|
}
|
|
914
914
|
if (hasFetchResponse && body instanceof globalThis.Response) {
|
|
915
915
|
this._status = this._status || body.status;
|
|
916
|
-
|
|
917
|
-
if (!this._headers[k]) this._headers[k] = v;
|
|
918
|
-
});
|
|
916
|
+
this.mergeFetchResponseHeaders(body);
|
|
919
917
|
return new globalThis.Response(method === "HEAD" ? null : body.body, {
|
|
920
918
|
status: this._status,
|
|
921
919
|
headers: this._buildWebHeaders()
|
|
@@ -942,6 +940,21 @@ var HttpResponse = class {
|
|
|
942
940
|
_buildWebHeaders() {
|
|
943
941
|
return recordToWebHeaders(this._headers);
|
|
944
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* Merges headers from a handler-returned fetch `Response` into the buffered headers.
|
|
945
|
+
* Explicitly buffered headers win. `set-cookie` is appended in array form so multiple
|
|
946
|
+
* cookies survive (`Headers` iteration would otherwise keep only the first).
|
|
947
|
+
*/
|
|
948
|
+
mergeFetchResponseHeaders(fetchResponse) {
|
|
949
|
+
fetchResponse.headers.forEach((value, key) => {
|
|
950
|
+
if (key !== "set-cookie" && !this._headers[key]) this._headers[key] = value;
|
|
951
|
+
});
|
|
952
|
+
const setCookies = typeof fetchResponse.headers.getSetCookie === "function" ? fetchResponse.headers.getSetCookie() : [];
|
|
953
|
+
if (setCookies.length > 0) {
|
|
954
|
+
const existing = this._headers["set-cookie"];
|
|
955
|
+
this._headers["set-cookie"] = existing ? [...Array.isArray(existing) ? existing : [existing], ...setCookies] : setCookies;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
945
958
|
renderBody() {
|
|
946
959
|
const body = this._body;
|
|
947
960
|
if (body === void 0 || body === null) return "";
|
|
@@ -1042,10 +1055,7 @@ var HttpResponse = class {
|
|
|
1042
1055
|
}
|
|
1043
1056
|
async sendFetchResponse(fetchResponse, method) {
|
|
1044
1057
|
this._status = this._status || fetchResponse.status;
|
|
1045
|
-
|
|
1046
|
-
if (fetchContentLength) this._headers["content-length"] = fetchContentLength;
|
|
1047
|
-
const fetchContentType = fetchResponse.headers.get("content-type");
|
|
1048
|
-
if (fetchContentType) this._headers["content-type"] = fetchContentType;
|
|
1058
|
+
this.mergeFetchResponseHeaders(fetchResponse);
|
|
1049
1059
|
this._res.writeHead(this._status, this._headers);
|
|
1050
1060
|
if (method === "HEAD") {
|
|
1051
1061
|
this._res.end();
|
|
@@ -1440,7 +1450,7 @@ function escapeHtml(value) {
|
|
|
1440
1450
|
//#endregion
|
|
1441
1451
|
//#region packages/event-http/src/response/wooks-http-response.ts
|
|
1442
1452
|
let framework = {
|
|
1443
|
-
version: "0.7.
|
|
1453
|
+
version: "0.7.20",
|
|
1444
1454
|
poweredBy: "wooksjs",
|
|
1445
1455
|
link: "https://wooks.moost.org/",
|
|
1446
1456
|
image: "https://wooks.moost.org/wooks-full-logo.svg"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.21",
|
|
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.21",
|
|
46
|
+
"wooks": "^0.7.21"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@prostojs/logger": "^0.4.3",
|
|
50
50
|
"@prostojs/router": "^0.3.4",
|
|
51
|
-
"@wooksjs/event-core": "^0.7.
|
|
52
|
-
"wooks": "^0.7.
|
|
51
|
+
"@wooksjs/event-core": "^0.7.21",
|
|
52
|
+
"wooks": "^0.7.21"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "rolldown -c ../../rolldown.config.mjs"
|