Newshot

Vercel Functions 现支持最大 20MiB 的请求体

AI summary

Vercel Functions 现已支持最大 20MiB 的入站请求体(此前为 4.5MB),目前处于公开测试阶段。启用方式为设置环境变量 VERCEL_SUPPORT_LARGE_REQUEST_BODY=1,该设置按环境对整个项目生效。启用后,项目内的函数需使用 4GB 的内存配置。该功能适用于 Node.js、Python 和 Bun 运行时的函数以及 Routing Middleware;Edge 运行时的函数与 Routing Middleware 仍保持 4.5MB 上限,请求体超出时返回 413。

Translation(model translation, not the source's own text)

文章标题:Vercel Functions 现已支持最大 20MiB 的请求体

正文: Vercel Functions 现在可以接受最大 20MiB 的入站请求体,此前上限为 4.5MB,该功能处于公开测试阶段。

要启用该功能,请设置环境变量 VERCEL_SUPPORT_LARGE_REQUEST_BODY=1。该选择项作用于设置它的环境中的整个项目,因此你可以先在 preview 环境测试更大的限制,然后再在生产环境启用。这要求项目的 functions 使用 4GB 的 performance memory 设置。它适用于 Node.js、Python 和 Bun 运行时上的 functions,以及 Routing Middleware。Edge 运行时上的 Functions 和 Routing Middleware 仍保持 4.5MB 的上限,并在请求体过大时返回 413,因此要将它们迁移到更大的限制,意味着需要切换到 Node.js 运行时(使用 runtime: 'nodejs'),或在 Next.js 中使用 proxy.ts。

当项目选择启用后,Routing Middleware 会收到请求头和元数据,但收不到请求体,这一点在项目级别强制执行。Middleware 仍会运行,仍能看见其他所有请求头,因此依赖请求体的 middleware 行为是唯一变得不可用的部分。这避免了将请求体发送两次(分别发给 middleware 和目标 function),否则会增加成本和首字节时间。

在处理较大的请求体时,请及时读取请求体,避免将其保留在内存中,以防止背压和内存问题。

在 Vercel Functions 限制文档中了解更多。

Only about 745 characters could be extracted — the rest did not come through (common on sites that need scrolling or a login). Read the original for the full piece.

Published by Vercel Blog
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗