@sveltejs/kit 1.0.0-next.478 → 1.0.0-next.480
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
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as set_cookie_parser from 'set-cookie-parser';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('http').IncomingMessage} req
|
|
5
|
+
* @param {number} [body_size_limit]
|
|
6
|
+
*/
|
|
7
|
+
function get_raw_body(req, body_size_limit) {
|
|
5
8
|
const h = req.headers;
|
|
6
9
|
|
|
7
10
|
if (!h['content-type']) {
|
|
@@ -11,11 +14,26 @@ function get_raw_body(req) {
|
|
|
11
14
|
const length = Number(h['content-length']);
|
|
12
15
|
|
|
13
16
|
// check if no request body
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
if (
|
|
18
|
+
(req.httpVersionMajor === 1 && isNaN(length) && h['transfer-encoding'] == null) ||
|
|
19
|
+
length === 0
|
|
20
|
+
) {
|
|
16
21
|
return null;
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
if (body_size_limit) {
|
|
25
|
+
if (!length) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Received content-length of ${length}. content-length must be provided when body size limit is specified.`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
if (length > body_size_limit) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
19
37
|
if (req.destroyed) {
|
|
20
38
|
const readable = new ReadableStream();
|
|
21
39
|
readable.cancel();
|
|
@@ -65,9 +83,9 @@ function get_raw_body(req) {
|
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
/** @type {import('@sveltejs/kit/node').getRequest} */
|
|
68
|
-
export async function getRequest(base,
|
|
69
|
-
let headers = /** @type {Record<string, string>} */ (
|
|
70
|
-
if (
|
|
86
|
+
export async function getRequest({ request, base, bodySizeLimit }) {
|
|
87
|
+
let headers = /** @type {Record<string, string>} */ (request.headers);
|
|
88
|
+
if (request.httpVersionMajor === 2) {
|
|
71
89
|
// we need to strip out the HTTP/2 pseudo-headers because node-fetch's
|
|
72
90
|
// Request implementation doesn't like them
|
|
73
91
|
// TODO is this still true with Node 18
|
|
@@ -78,10 +96,10 @@ export async function getRequest(base, req) {
|
|
|
78
96
|
delete headers[':scheme'];
|
|
79
97
|
}
|
|
80
98
|
|
|
81
|
-
return new Request(base +
|
|
82
|
-
method:
|
|
99
|
+
return new Request(base + request.url, {
|
|
100
|
+
method: request.method,
|
|
83
101
|
headers,
|
|
84
|
-
body: get_raw_body(
|
|
102
|
+
body: get_raw_body(request, bodySizeLimit)
|
|
85
103
|
});
|
|
86
104
|
}
|
|
87
105
|
|
|
@@ -391,10 +391,13 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
391
391
|
let request;
|
|
392
392
|
|
|
393
393
|
try {
|
|
394
|
-
request = await getRequest(
|
|
394
|
+
request = await getRequest({
|
|
395
|
+
base,
|
|
396
|
+
request: req
|
|
397
|
+
});
|
|
395
398
|
} catch (/** @type {any} */ err) {
|
|
396
399
|
res.statusCode = err.status || 400;
|
|
397
|
-
return res.end(err.
|
|
400
|
+
return res.end(err.message || 'Invalid request body');
|
|
398
401
|
}
|
|
399
402
|
|
|
400
403
|
const template = load_template(cwd, svelte_config);
|
|
@@ -131,10 +131,13 @@ export async function preview(vite, vite_config, svelte_config) {
|
|
|
131
131
|
let request;
|
|
132
132
|
|
|
133
133
|
try {
|
|
134
|
-
request = await getRequest(
|
|
134
|
+
request = await getRequest({
|
|
135
|
+
base: `${protocol}://${host}`,
|
|
136
|
+
request: req
|
|
137
|
+
});
|
|
135
138
|
} catch (/** @type {any} */ err) {
|
|
136
139
|
res.statusCode = err.status || 400;
|
|
137
|
-
return res.end(err.
|
|
140
|
+
return res.end(err.message || 'Invalid request body');
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
setResponse(
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -19,7 +19,7 @@ export const applyAction = ssr ? guard('applyAction') : client.apply_action;
|
|
|
19
19
|
export function enhance(form, submit = () => {}) {
|
|
20
20
|
/**
|
|
21
21
|
* @param {{
|
|
22
|
-
* action:
|
|
22
|
+
* action: URL;
|
|
23
23
|
* result: import('types').ActionResult;
|
|
24
24
|
* }} opts
|
|
25
25
|
*/
|
|
@@ -28,7 +28,7 @@ export function enhance(form, submit = () => {}) {
|
|
|
28
28
|
await invalidateAll();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if (location.origin + location.pathname === action.
|
|
31
|
+
if (location.origin + location.pathname === action.origin + action.pathname) {
|
|
32
32
|
applyAction(result);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
@@ -37,10 +37,13 @@ export function enhance(form, submit = () => {}) {
|
|
|
37
37
|
async function handle_submit(event) {
|
|
38
38
|
event.preventDefault();
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const action = new URL(
|
|
41
|
+
// We can't do submitter.formAction directly because that property is always set
|
|
42
|
+
event.submitter?.hasAttribute('formaction')
|
|
43
|
+
? /** @type {HTMLButtonElement | HTMLInputElement} */ (event.submitter).formAction
|
|
44
|
+
: form.action
|
|
45
|
+
);
|
|
46
|
+
|
|
44
47
|
const data = new FormData(form);
|
|
45
48
|
const controller = new AbortController();
|
|
46
49
|
|
package/types/ambient.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ declare module '$app/forms' {
|
|
|
99
99
|
Success extends Record<string, unknown> | undefined = Record<string, any>,
|
|
100
100
|
Invalid extends Record<string, unknown> | undefined = Record<string, any>
|
|
101
101
|
> = (input: {
|
|
102
|
-
action:
|
|
102
|
+
action: URL;
|
|
103
103
|
data: FormData;
|
|
104
104
|
form: HTMLFormElement;
|
|
105
105
|
controller: AbortController;
|
|
@@ -108,7 +108,7 @@ declare module '$app/forms' {
|
|
|
108
108
|
| void
|
|
109
109
|
| ((opts: {
|
|
110
110
|
form: HTMLFormElement;
|
|
111
|
-
action:
|
|
111
|
+
action: URL;
|
|
112
112
|
result: ActionResult<Success, Invalid>;
|
|
113
113
|
}) => void);
|
|
114
114
|
|
|
@@ -408,10 +408,11 @@ declare module '@sveltejs/kit/node/polyfills' {
|
|
|
408
408
|
* Utilities used by adapters for Node-like environments.
|
|
409
409
|
*/
|
|
410
410
|
declare module '@sveltejs/kit/node' {
|
|
411
|
-
export function getRequest(
|
|
412
|
-
base: string
|
|
413
|
-
request: import('http').IncomingMessage
|
|
414
|
-
|
|
411
|
+
export function getRequest(opts: {
|
|
412
|
+
base: string;
|
|
413
|
+
request: import('http').IncomingMessage;
|
|
414
|
+
bodySizeLimit?: number;
|
|
415
|
+
}): Promise<Request>;
|
|
415
416
|
export function setResponse(res: import('http').ServerResponse, response: Response): void;
|
|
416
417
|
}
|
|
417
418
|
|