Skip to content

feat(node): resolve tmp file upload body limits per request - #1881

Merged
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:claude/dynamic-body-size-limit-d89566
Aug 17, 2026
Merged

feat(node): resolve tmp file upload body limits per request#1881
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:claude/dynamic-body-size-limit-d89566

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 17, 2026

Copy link
Copy Markdown
Member

TmpFileUploadHandlerPlugin's maxBodySize now accepts a function, sync or async, alongside the fixed object it already took. The function receives the routing interceptor options (context, request, prefix), so an upload allowance can follow the request that carries it, such as a larger file limit for an authenticated user than for a guest.

Behavior

  • A fixed maxBodySize object behaves exactly as before, and remains the default when the option is omitted.
  • The resolver runs only when a body is actually parsed, so a request that carries no body never pays for the lookup.
  • It receives the request as it arrived, before the plugin wraps body resolution.
  • All three limits now come from one resolution per parsed body, so a multipart body enforces memory, file, and their combined total from a single consistent snapshot.

Types

TmpFileUploadHandlerPluginOptions is now generic in the handler context, matching BatchHandlerPluginOptions. Existing call sites that pass a fixed object keep compiling untouched; new TmpFileUploadHandlerPlugin<AppContext>({ ... }) types context inside the resolver.

Testing

Three cases cover context-driven limits rejecting a guest and admitting an authenticated user for memory-parsed bodies and for spooled files, with temporary files still cleaned up on rejection, plus a case asserting the resolver is skipped when no body is parsed. 145 tests pass across packages/node; root type check and lint are clean.

@vercel

vercel Bot commented Aug 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 17, 2026 8:57am

@pkg-pr-new

pkg-pr-new Bot commented Aug 17, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1881

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1881

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1881

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1881

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1881

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1881

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1881

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1881

@orpc/hibernation

npm i https://pkg.pr.new/@orpc/hibernation@1881

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1881

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1881

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1881

@orpc/node

npm i https://pkg.pr.new/@orpc/node@1881

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1881

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1881

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1881

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1881

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1881

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1881

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1881

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1881

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1881

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1881

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1881

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1881

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1881

commit: f5d7d38

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing dinwwwh:claude/dynamic-body-size-limit-d89566 (f5d7d38) with main (f02cd98)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • maxBodySize resolver: TmpFileUploadHandlerPluginOptions<T> is now generic in the handler context and maxBodySize accepts either the fixed object or a sync/async resolver over StandardHandlerRoutingInterceptorOptions<T> (context, request, prefix), matching BatchHandlerPluginOptions.
  • resolveBody refactor: now takes the full interceptorOptions and resolves limits via a single await value(...) per parsed body, feeding all three limits and the multipart total from one snapshot.
  • 'none' early return: a body-less request skips the resolver and resolves via the standard parser — preserving the old catch-all behavior while avoiding needless lookups.
  • Tests: context-driven guest-reject / authed-admit for memory and spooled bodies, tmp cleanup on rejection, and a no-body-skips-resolver case.
  • Docs: new "Per-Request Limits" section.

I verified the type shape (StandardHandlerRoutingInterceptorOptions<T> is exactly { prefix?, context, request }, so the resolver's runtime args match its signature), the closed hint union (json | form-data | url-search-params | event-stream | octet-stream | file | none — the fallthrough to parseLimitedBody(stream) is behavior-preserving, since 'none' is the only prior catch-all member and is now handled explicitly), and that the tests genuinely fail without per-context resolution.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit 5f023ca into middleapi:main Aug 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant