Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow streaming with body_size_limit #6702

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/adapter-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Instead, we read from the _right_, accounting for the number of trusted proxies.

### `BODY_SIZE_LIMIT`

The maximum request body size to accept in bytes. Defaults to 512kb. This option does not allow streaming. You can disable this option with a value of 0 and implement a custom check in [`handle`](https://kit.svelte.dev/docs/hooks#server-hooks-handle) if you need something more advanced.
The maximum request body size to accept in bytes. Defaults to 512kb. You can disable this option with a value of 0 and implement a custom check in [`handle`](https://kit.svelte.dev/docs/hooks#server-hooks-handle) if you need something more advanced.
benmccann marked this conversation as resolved.
Show resolved Hide resolved

## Options

Expand Down
11 changes: 4 additions & 7 deletions packages/kit/src/exports/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function get_raw_body(req, body_size_limit) {
return null;
}

const length = Number(h['content-length']);
let length = Number(h['content-length']);

// check if no request body
if (
Expand All @@ -23,11 +23,8 @@ function get_raw_body(req, body_size_limit) {

if (body_size_limit) {
if (!length) {
throw new Error(
`Received content-length of ${length}. content-length must be provided when body size limit is specified.`
);
}
if (length > body_size_limit) {
length = body_size_limit;
} else if (length > body_size_limit) {
throw new Error(
`Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`
);
Expand Down Expand Up @@ -59,7 +56,7 @@ function get_raw_body(req, body_size_limit) {

size += chunk.length;
if (size > length) {
controller.error(new Error('content-length exceeded'));
req.destroy(new Error('request body size exceeded'));
benmccann marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down