Skip to content

refactor(helpers): extract duplicated setFormDataHeaders into a shared helper - #11062

Merged
jasonsaayman merged 1 commit into
axios:v1.xfrom
QodeXcli:refactor/dedupe-set-form-data-headers
Jul 15, 2026
Merged

jasonsaayman merged 1 commit into
axios:v1.xfrom
QodeXcli:refactor/dedupe-set-form-data-headers

Conversation

@QodeXcli

@QodeXcli QodeXcli commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

lib/helpers/resolveConfig.js and lib/adapters/http.js each carry their own copy of setFormDataHeaders (plus the FORM_DATA_CONTENT_HEADERS list). The two copies are identical except that the resolveConfig.js one guards against a missing headers object (formHeaders || {}).

This PR moves the function to lib/helpers/setFormDataHeaders.js (one helper per file, matching the rest of lib/helpers) and imports it from both call sites, keeping the defensive variant — so the http adapter now also tolerates a FormData implementation whose getHeaders() returns undefined.

No other behavior change: both call sites already invoke it with the same (headers, data.getHeaders(), formDataHeaderPolicy) shape.

Testing

  • npm run lint clean
  • vitest run --project unit: 946 passed — including all 89 form-data-related tests that exercise both touched call paths. (The two failures on my machine — fetch failed error as an AxiosError with ERR_NETWORK and the DNS should handle errors case — fail identically on an unmodified checkout; they are environment/DNS-dependent, not related to this change.)

Found with an automated near-duplicate-helper detector I'm building (QodeX); the consolidation itself was reviewed and applied by hand.


Summary by cubic

Centralized FormData header handling by extracting setFormDataHeaders into lib/core/setFormDataHeaders.js and using it in both resolveConfig and the Node HTTP adapter. Behavior is unchanged; the adapter now also tolerates FormData#getHeaders() returning undefined when formDataHeaderPolicy: 'content-only'.

Description

  • Summary of changes
    • Added lib/core/setFormDataHeaders.js and imported it in lib/helpers/resolveConfig.js and lib/adapters/http.js.
    • Preserved content-only policy behavior and the guard for missing formHeaders.
  • Reasoning
    • Removed duplicate logic and kept axios-specific behavior in core rather than expanding generic helpers.
  • Additional context
    • Both call sites already call it as (headers, data.getHeaders(), formDataHeaderPolicy). Pre-release changelog notes the Node robustness fix.

Docs

  • No user-facing changes. Optionally add a short note in /docs/form-data.md confirming both environments honor formDataHeaderPolicy and tolerate missing form-data headers.

Testing

  • Added a Node HTTP regression test to ignore undefined getHeaders() results with content-only policy.
  • Existing unit tests continue to cover both paths.

Semantic version impact

  • Patch: internal refactor with no API changes; minor robustness improvement only.

Written for commit 14c01a0. Summary will update on new commits.

Review in cubic

@QodeXcli
QodeXcli requested a review from jasonsaayman as a code owner July 2, 2026 01:22
QodeXcli added a commit to QodeXcli/QodeX that referenced this pull request Jul 2, 2026
…/axios#11062) (#97)

The near-dupe finding on axios (setFormDataHeaders duplicated across resolveConfig.js and
adapters/http.js) was reviewed by hand, consolidated into lib/helpers/setFormDataHeaders.js
(keeping the defensive variant), verified against axios's own suite (lint clean, all 89
form-data tests green, the 2 remaining failures reproduced identically on an unmodified
checkout), and submitted upstream: axios/axios#11062.

Also documents what we deliberately did NOT submit — the hono clusters are behaviorally
distinct on inspection (crypto branching; intentional URL-encoding difference) and the zod
family is arguably deliberate API symmetry. Detection said "similar"; judgment said "leave
them" — the same mechanical-evidence / human-judgment split maintain runs on.

Co-authored-by: Louise Lau <QodeXcli@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai 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 issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

QodeXcli added a commit to QodeXcli/QodeX that referenced this pull request Jul 2, 2026
…s + exports cheat-sheet (#103)

Completes the export story — every maintain artifact can now leave the terminal in the format
its audience consumes:

- maintain-audit --pdf: the auditor-facing one-pager — verification status up top (chain
  INTACT/BROKEN, head match, signature VALID/INVALID/unsigned, overall PASS/FAIL), then the full
  run chain as a readable table (seq, date, scope, outcome, files, checks, PR link), and the
  offline-verify instruction at the foot. buildAuditPdfBlocks is PURE (takes the verdict from
  verifyAuditLog); composes with --sign.
- pdf-lite: "Page N of M" footers on multi-page documents (one-pagers stay clean).
- ADOPTION.md "Every export, one place": an audience→command→artifact table covering demo/
  report/audit/history exports; notes all PDFs come from the dependency-free writer.

(axios/axios#11062 still OPEN with no review comments — the "merged upstream" docs update waits
for the actual merge, honestly.)

Co-authored-by: Louise Lau <QodeXcli@users.noreply.github.com>

@Ziiyodullayevv Ziiyodullayevv 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.

Good refactoring. Extracting duplicated setFormDataHeaders into a shared helper reduces code duplication and improves maintainability.

resolveConfig and the HTTP adapter carried separate copies of the formDataHeaderPolicy logic. Move that axios-specific behavior into lib/core/setFormDataHeaders.js so both call sites share the same filtering without expanding the generic helpers layer.

Keep the defensive handling for missing FormData headers, add Node HTTP regression coverage, and record the user-visible robustness fix in the pre-release changelog.
@jasonsaayman
jasonsaayman force-pushed the refactor/dedupe-set-form-data-headers branch from c94a93f to 14c01a0 Compare July 15, 2026 14:13
@jasonsaayman
jasonsaayman merged commit 58b16c8 into axios:v1.x Jul 15, 2026
25 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.

3 participants