Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

#127 feat(multipart): pass raw part headers to file and field events - #231

Open
macgbluedev wants to merge 2 commits into
fastify:mainfrom
macgbluedev:feat/127-multipart-part-headers
Open

macgbluedev wants to merge 2 commits into
fastify:mainfrom
macgbluedev:feat/127-multipart-part-headers

Conversation

@macgbluedev

Copy link
Copy Markdown

Motivation

Exposing the full part headers lets projects built on top of this library enrich their responses with that information.

I came to this repo through supabase/storage#816, where Supabase Storage uses Fastify as its server.

The discussion in the linked issue (#127 ) mentions that nodejs/undici had the same need. Since v6 undici ships its own multipart parser and only keeps busboy as a dev dependency.

Checklist

Refs: #127

@macgbluedev macgbluedev mentioned this pull request Oct 3, 2026
2 tasks done
Fixes the @stylistic/eol-last lint error that failed CI.

Refs: fastify#127

@yxshee yxshee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looked at this while working on two Dicer fixes nearby; the change itself is small and additive.

  • The header object passed through is the one HeaderParser._finish hands to the part, so it is not reused between parts and the listener can keep it. It is created with Object.create(null), which is good for __proto__/constructor keys but means headers.hasOwnProperty('x-custom') throws; worth one sentence in the README ('x-custom' in headers or Object.hasOwn work).
  • Adding a trailing argument keeps every existing listener working, including undici's positional on('file', (name, stream, filename, encoding, mimeType) => …); nothing in lib/ reads arguments.length, so the extra argument is invisible to current callers.
  • The new test covers repeated headers (X-Custom: a, X-Custom: b) and that the raw content-type keeps its casing and parameters while mimeType is lower-cased without them, which is exactly the distinction a consumer would rely on. One more assertion worth adding: a part whose header block has a folded header (X-Custom: a\r\n b), since _parseHeader joins the continuation into the last value and callers of this new API will see that joined string.
  • BusboyPartHeaders = Record<string, string[]> matches what _parseHeader produces.

No objections from me; the README note and the folded-header assertion are the only things I would add.

This branch has not been deployed

No deployments
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.

2 participants