@fedify/fastify 2.0.29-dev.2018 → 2.0.29-dev.2046
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 +24 -2
- package/dist/index.js +24 -2
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -94,13 +94,35 @@ function toWebRequest(fastifyReq) {
|
|
|
94
94
|
const headers = new Headers();
|
|
95
95
|
for (const [key, value] of Object.entries(fastifyReq.raw.headers)) if (Array.isArray(value)) for (const v of value) headers.append(key, v);
|
|
96
96
|
else if (value !== void 0) headers.set(key, String(value));
|
|
97
|
-
const body = fastifyReq.method === "GET" || fastifyReq.method === "HEAD" ? void 0 : fastifyReq.body !== void 0 ? typeof fastifyReq.body === "string" ? fastifyReq.body : JSON.stringify(fastifyReq.body) :
|
|
97
|
+
const body = fastifyReq.method === "GET" || fastifyReq.method === "HEAD" ? void 0 : fastifyReq.body !== void 0 ? typeof fastifyReq.body === "string" ? fastifyReq.body : JSON.stringify(fastifyReq.body) : lazyRequestBody(fastifyReq.raw);
|
|
98
98
|
return new Request(url, {
|
|
99
99
|
method: fastifyReq.method,
|
|
100
100
|
headers,
|
|
101
|
-
body
|
|
101
|
+
body,
|
|
102
|
+
duplex: "half"
|
|
102
103
|
});
|
|
103
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Wraps the raw `IncomingMessage` in a `ReadableStream` that stays inert until
|
|
107
|
+
* first read. The `Request` is built in the `onRequest` hook, before Fedify
|
|
108
|
+
* decides whether it handles the request; an eager `Readable.toWeb()` would
|
|
109
|
+
* start draining the socket and break Fastify's own body parsing of the
|
|
110
|
+
* declined requests.
|
|
111
|
+
*/
|
|
112
|
+
function lazyRequestBody(message) {
|
|
113
|
+
let reader;
|
|
114
|
+
return new ReadableStream({
|
|
115
|
+
async pull(controller) {
|
|
116
|
+
reader ??= node_stream.Readable.toWeb(message).getReader();
|
|
117
|
+
const { done, value } = await reader.read();
|
|
118
|
+
if (done) controller.close();
|
|
119
|
+
else controller.enqueue(value);
|
|
120
|
+
},
|
|
121
|
+
cancel(reason) {
|
|
122
|
+
return reader?.cancel(reason);
|
|
123
|
+
}
|
|
124
|
+
}, { highWaterMark: 0 });
|
|
125
|
+
}
|
|
104
126
|
//#endregion
|
|
105
127
|
exports.default = fedifyPlugin;
|
|
106
128
|
exports.fedifyPlugin = fedifyPlugin;
|
package/dist/index.js
CHANGED
|
@@ -67,12 +67,34 @@ function toWebRequest(fastifyReq) {
|
|
|
67
67
|
const headers = new Headers();
|
|
68
68
|
for (const [key, value] of Object.entries(fastifyReq.raw.headers)) if (Array.isArray(value)) for (const v of value) headers.append(key, v);
|
|
69
69
|
else if (value !== void 0) headers.set(key, String(value));
|
|
70
|
-
const body = fastifyReq.method === "GET" || fastifyReq.method === "HEAD" ? void 0 : fastifyReq.body !== void 0 ? typeof fastifyReq.body === "string" ? fastifyReq.body : JSON.stringify(fastifyReq.body) :
|
|
70
|
+
const body = fastifyReq.method === "GET" || fastifyReq.method === "HEAD" ? void 0 : fastifyReq.body !== void 0 ? typeof fastifyReq.body === "string" ? fastifyReq.body : JSON.stringify(fastifyReq.body) : lazyRequestBody(fastifyReq.raw);
|
|
71
71
|
return new Request(url, {
|
|
72
72
|
method: fastifyReq.method,
|
|
73
73
|
headers,
|
|
74
|
-
body
|
|
74
|
+
body,
|
|
75
|
+
duplex: "half"
|
|
75
76
|
});
|
|
76
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Wraps the raw `IncomingMessage` in a `ReadableStream` that stays inert until
|
|
80
|
+
* first read. The `Request` is built in the `onRequest` hook, before Fedify
|
|
81
|
+
* decides whether it handles the request; an eager `Readable.toWeb()` would
|
|
82
|
+
* start draining the socket and break Fastify's own body parsing of the
|
|
83
|
+
* declined requests.
|
|
84
|
+
*/
|
|
85
|
+
function lazyRequestBody(message) {
|
|
86
|
+
let reader;
|
|
87
|
+
return new ReadableStream({
|
|
88
|
+
async pull(controller) {
|
|
89
|
+
reader ??= Readable.toWeb(message).getReader();
|
|
90
|
+
const { done, value } = await reader.read();
|
|
91
|
+
if (done) controller.close();
|
|
92
|
+
else controller.enqueue(value);
|
|
93
|
+
},
|
|
94
|
+
cancel(reason) {
|
|
95
|
+
return reader?.cancel(reason);
|
|
96
|
+
}
|
|
97
|
+
}, { highWaterMark: 0 });
|
|
98
|
+
}
|
|
77
99
|
//#endregion
|
|
78
100
|
export { fedifyPlugin as default, fedifyPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/fastify",
|
|
3
|
-
"version": "2.0.29-dev.
|
|
3
|
+
"version": "2.0.29-dev.2046+5211d803",
|
|
4
4
|
"description": "Integrate Fedify with Fastify",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"fastify": "^5.2.0",
|
|
51
|
-
"@fedify/fedify": "^2.0.29-dev.
|
|
51
|
+
"@fedify/fedify": "^2.0.29-dev.2046+5211d803"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "^22.17.0",
|