Skip to content

multipart: expose parsed Content-Disposition params on file/field info - #387

Open
Martin-Luther wants to merge 1 commit into
mscdex:masterfrom
gina-io:upstream-pr
Open

Martin-Luther wants to merge 1 commit into
mscdex:masterfrom
gina-io:upstream-pr

Conversation

@Martin-Luther

Copy link
Copy Markdown

Adds the already-parsed Content-Disposition parameters to the info object that
is passed to the file and field events, as info.dispositionParams.

Motivation

A multipart part's Content-Disposition header can carry parameters beyond name
and filename. busboy already parses the complete parameter list via parseParams,
but only surfaces name and filename — so a consumer that needs any other
parameter has to re-parse the raw header itself.

That duplication is the problem: a second parser has to re-implement RFC 2231
continuations and charset-tagged values (name*=utf-8''...) to stay consistent with
busboy, and any divergence between the two silently misattributes parts. Exposing the
value busboy has already computed removes the need for a second parser entirely.

What changes

  • lib/types/multipart.js: the parsed disp.params is retained per part and included
    in the info object emitted with the file and field events, as
    dispositionParams. It is null for a part with no Content-Disposition header.

That is the whole change — 10 lines. No new options, no signature changes, nothing
removed or renamed.

Compatibility

Strictly additive: one new property on an object that is already passed to the
listener. info.name / info.filename / info.encoding / info.mimeType and every
existing event signature are untouched, so existing consumers are unaffected whether
or not they read the new property.

Tests

  • test/test-types-multipart-disposition-params.js (new) — covers the exposed
    parameters for both file and field parts, including a part with no
    Content-Disposition header.
  • test/test-types-multipart.js — extended to assert the new property alongside the
    existing expectations.
  • test/test-types-multipart-charsets.js, test/test-types-multipart-stream-pause.js
    — updated where they assert the full info shape.

Related

#183 asks for the same underlying capability (making additional multipart header
information available). This PR is the narrower form of that request: rather than
surfacing arbitrary headers, it exposes only what parseParams already produces for
Content-Disposition, which keeps the surface small and avoids any new parsing.

Surface the full set of parsed Content-Disposition parameters for each part as info.dispositionParams on both the file and field events. This exposes the standard parameters (name, filename) as well as any custom parameter (for example a group tag) without changing any existing field of the info object.
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