@standardserver/node 0.0.10 → 0.0.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 +27 -24
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -20,80 +20,83 @@ async function toStandardBody(req, options = {}) {
|
|
|
20
20
|
const hint = flattenStandardHeader(req.headers["standard-server"]) ?? options?.hint;
|
|
21
21
|
const contentType = req.headers["content-type"];
|
|
22
22
|
const mimeType = contentType?.split(";")[0]?.trim();
|
|
23
|
-
const contentDisposition = req.headers["content-disposition"];
|
|
24
23
|
const contentLength = req.headers["content-length"];
|
|
25
|
-
if (
|
|
24
|
+
if (req.body !== void 0) {
|
|
25
|
+
return req.body;
|
|
26
|
+
}
|
|
27
|
+
if (hint === "none" || hint === void 0 && mimeType === void 0 && (contentLength === "0" || contentLength === void 0)) {
|
|
26
28
|
return void 0;
|
|
27
29
|
}
|
|
28
30
|
if (hint === void 0 && EMPTY_BODY_METHOD_SET.has(toStandardMethod(req.method))) {
|
|
29
31
|
return void 0;
|
|
30
32
|
}
|
|
31
|
-
if (req.body !== void 0) {
|
|
32
|
-
return req.body;
|
|
33
|
-
}
|
|
34
33
|
if (!req.readable) {
|
|
35
34
|
throw new TypeError("Failed to read body: body stream already read or destroyed");
|
|
36
35
|
}
|
|
37
|
-
if (hint === "json" || hint === void 0 &&
|
|
36
|
+
if (hint === "json" || hint === void 0 && mimeType === "application/json") {
|
|
38
37
|
const text = await _streamToString(req);
|
|
39
38
|
return parseEmptyableJSON(text);
|
|
40
39
|
}
|
|
41
|
-
if (hint === "form-data" || hint === void 0 &&
|
|
40
|
+
if (hint === "form-data" || hint === void 0 && mimeType === "multipart/form-data") {
|
|
42
41
|
return _streamToFormData(req, contentType);
|
|
43
42
|
}
|
|
44
|
-
if (hint === "url-search-params" || hint === void 0 &&
|
|
43
|
+
if (hint === "url-search-params" || hint === void 0 && mimeType === "application/x-www-form-urlencoded") {
|
|
45
44
|
const text = await _streamToString(req);
|
|
46
45
|
return new URLSearchParams(text);
|
|
47
46
|
}
|
|
48
|
-
if (hint === "event-stream" || hint === void 0 &&
|
|
47
|
+
if (hint === "event-stream" || hint === void 0 && mimeType === "text/event-stream") {
|
|
49
48
|
return toEventIterator(req);
|
|
50
49
|
}
|
|
51
|
-
if (hint === "file" || hint === void 0 &&
|
|
50
|
+
if (hint === "file" || hint === void 0 && contentLength !== void 0) {
|
|
51
|
+
const contentDisposition = req.headers["content-disposition"];
|
|
52
52
|
const fileName = contentDisposition !== void 0 ? getFilenameFromContentDisposition(contentDisposition) : void 0;
|
|
53
53
|
return _streamToFile(req, fileName ?? "blob", contentType ?? "");
|
|
54
54
|
}
|
|
55
55
|
return Readable.toWeb(req);
|
|
56
56
|
}
|
|
57
57
|
async function toNodeHttpBody(body, headers, options = {}) {
|
|
58
|
-
|
|
58
|
+
const originalContentType = headers["content-type"];
|
|
59
|
+
const originalContentLength = headers["content-length"];
|
|
60
|
+
headers = {
|
|
61
|
+
...headers,
|
|
62
|
+
"standard-server": void 0,
|
|
63
|
+
"content-type": void 0,
|
|
64
|
+
"content-length": void 0
|
|
65
|
+
};
|
|
59
66
|
if (body === void 0) {
|
|
60
|
-
headers["standard-server"] = "none";
|
|
61
67
|
return [void 0, headers];
|
|
62
68
|
}
|
|
63
69
|
if (body instanceof ReadableStream) {
|
|
64
70
|
headers["standard-server"] = "octet-stream";
|
|
65
|
-
headers["content-type"]
|
|
71
|
+
headers["content-type"] = originalContentType ?? "application/octet-stream";
|
|
72
|
+
headers["content-length"] = originalContentLength;
|
|
66
73
|
return [Readable.fromWeb(body), headers];
|
|
67
74
|
}
|
|
68
75
|
if (body instanceof Blob) {
|
|
69
76
|
headers["standard-server"] = "file";
|
|
70
|
-
headers["content-type"]
|
|
77
|
+
headers["content-type"] = body.type;
|
|
71
78
|
headers["content-disposition"] ??= generateContentDisposition(body instanceof File ? body.name : "blob");
|
|
72
79
|
if (!Number.isNaN(body.size)) {
|
|
73
|
-
headers["content-length"]
|
|
80
|
+
headers["content-length"] = body.size.toString();
|
|
74
81
|
}
|
|
75
82
|
return [Readable.fromWeb(body.stream()), headers];
|
|
76
83
|
}
|
|
77
84
|
if (body instanceof FormData) {
|
|
78
85
|
const response = new Response(body);
|
|
79
86
|
const blob = await response.blob();
|
|
80
|
-
headers["
|
|
81
|
-
headers["content-
|
|
82
|
-
headers["content-length"] ??= blob.size.toString();
|
|
87
|
+
headers["content-type"] = blob.type;
|
|
88
|
+
headers["content-length"] = blob.size.toString();
|
|
83
89
|
return [Readable.fromWeb(blob.stream()), headers];
|
|
84
90
|
}
|
|
85
91
|
if (body instanceof URLSearchParams) {
|
|
86
|
-
headers["
|
|
87
|
-
headers["content-type"] ??= "application/x-www-form-urlencoded";
|
|
92
|
+
headers["content-type"] = "application/x-www-form-urlencoded";
|
|
88
93
|
return [body.toString(), headers];
|
|
89
94
|
}
|
|
90
95
|
if (isAsyncIteratorObject(body)) {
|
|
91
|
-
headers["
|
|
92
|
-
headers["content-type"] ??= "text/event-stream";
|
|
96
|
+
headers["content-type"] = "text/event-stream";
|
|
93
97
|
return [toEventStream(body, options.eventStream), headers];
|
|
94
98
|
}
|
|
95
|
-
headers["
|
|
96
|
-
headers["content-type"] ??= "application/json";
|
|
99
|
+
headers["content-type"] = "application/json";
|
|
97
100
|
return [stringifyJSON(body), headers];
|
|
98
101
|
}
|
|
99
102
|
function _streamToFormData(stream, contentType) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@standardserver/node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://standardserver.dev",
|
|
7
7
|
"repository": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@standardserver/core": "0.0.
|
|
24
|
-
"@standardserver/
|
|
25
|
-
"@standardserver/
|
|
23
|
+
"@standardserver/core": "0.0.11",
|
|
24
|
+
"@standardserver/shared": "0.0.11",
|
|
25
|
+
"@standardserver/fetch": "0.0.11"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^25.0.3",
|