@server/next 0.25.6 → 0.25.7
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/package.json +1 -1
- package/src/context/parseBody.js +10 -4
- package/src/parseResponse.js +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.7",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/context/parseBody.js
CHANGED
|
@@ -2,6 +2,14 @@ import { createId } from "../helpers/index.js";
|
|
|
2
2
|
|
|
3
3
|
function getBoundary(header) {
|
|
4
4
|
if (!header) return null;
|
|
5
|
+
|
|
6
|
+
// When we set the `content-type` manually on fetch(), it won't include the
|
|
7
|
+
// boundary and it's recommended not to set it manually:
|
|
8
|
+
// https://stackoverflow.com/q/39280438/938236
|
|
9
|
+
if (header.includes("multipart/form-data") && !header.includes("boundary=")) {
|
|
10
|
+
console.error("Do not set the `Content-Type` manually for FormData");
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
const items = header.split(";");
|
|
6
14
|
for (const item of items) {
|
|
7
15
|
const trimmedItem = item.trim();
|
|
@@ -43,10 +51,8 @@ function splitBuffer(buffer, delimiter) {
|
|
|
43
51
|
const BREAK = "\r\n\r\n";
|
|
44
52
|
|
|
45
53
|
export default async function parseBody(raw, contentType, bucket) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
? Buffer.from(raw)
|
|
49
|
-
: Buffer.from(await raw.arrayBuffer());
|
|
54
|
+
const baseBuffer = typeof raw === "string" ? raw : await raw.arrayBuffer();
|
|
55
|
+
const rawBuffer = Buffer.from(baseBuffer);
|
|
50
56
|
if (!rawBuffer) return {};
|
|
51
57
|
|
|
52
58
|
if (!contentType || /text\/plain/.test(contentType)) {
|
package/src/parseResponse.js
CHANGED
|
@@ -14,6 +14,10 @@ export default async function parseResponse(out, ctx) {
|
|
|
14
14
|
out = new Response(out, { headers: { "Content-Type": blob.type } });
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
if (out instanceof ReadableStream) {
|
|
18
|
+
out = new Response(out);
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
// A plain number is a status code
|
|
18
22
|
if (typeof out === "number") {
|
|
19
23
|
out = new Response(undefined, { status: out });
|
|
@@ -30,6 +34,18 @@ export default async function parseResponse(out, ctx) {
|
|
|
30
34
|
out = json(out);
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
// The output from fetch(), create a copy of it into a new response
|
|
38
|
+
if (out instanceof Response && out.url && out.body) {
|
|
39
|
+
out = new Response(out.body, {
|
|
40
|
+
status: 200,
|
|
41
|
+
headers: out.headers,
|
|
42
|
+
});
|
|
43
|
+
if (/^(br|gzip)$/.test(out.headers.get("content-encoding"))) {
|
|
44
|
+
console.warn("Compression not yet supported for response");
|
|
45
|
+
out.headers.delete("content-encoding");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
if (!(out instanceof Response)) {
|
|
34
50
|
throw new Error(`Invalid response type ${out}`);
|
|
35
51
|
}
|