Skip to content

Replace deprecated undici formData() method with @fastify/busboy implementation #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: v4.x
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 25, 2025

This PR addresses the deprecation of undici's formData() method by implementing the recommended alternative using @fastify/busboy.

Background

Undici v5 is EOL as of April 30, 2025, and in v6+ the formData() method was marked as deprecated. The method is still present in v7 but will likely be removed in future releases. Undici recommends using @fastify/busboy for parsing multipart/form-data in server environments.

Changes Made

  1. Added @fastify/busboy dependency - The recommended library for form data parsing
  2. Created src/http/formDataParser.ts - Custom implementation that handles:
    • multipart/form-data parsing using Busboy
    • application/x-www-form-urlencoded parsing using URLSearchParams
    • Proper error handling for unsupported content types
  3. Updated HttpRequest.formData() - Replaced deprecated undici method call
  4. Updated HttpResponse.formData() - Replaced deprecated undici method call
  5. Removed deprecation ESLint suppressions - No longer needed

API Compatibility

The new implementation maintains 100% backward compatibility with the existing FormData API:

// All existing usage continues to work unchanged
const form = await request.formData();
const name = form.get('name');
const file = form.get('upload') as File;
const allValues = form.getAll('duplicateField');

Test Coverage

All existing tests continue to pass, covering:

  • ✅ Basic multipart form field parsing
  • ✅ File uploads with filename and content type preservation
  • ✅ Duplicate field name handling (getAll() support)
  • ✅ URL-encoded form data parsing
  • ✅ Error handling for unsupported content types

Example Usage

The new parser handles the same scenarios as before:

// Multipart form data
const multipartForm = await request.formData();
console.log(multipartForm.get('username')); // Works as before

// URL-encoded data
const urlencodedForm = await request.formData(); 
console.log(urlencodedForm.get('email')); // Works as before

// File uploads
const file = multipartForm.get('attachment') as File;
console.log(file.name, file.type); // Preserves metadata

This change ensures Azure Functions is prepared for future undici versions and follows the library's recommended migration path.

Fixes #331.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@swapnil-nagar swapnil-nagar marked this pull request as ready for review June 25, 2025 03:29
@swapnil-nagar swapnil-nagar marked this pull request as draft June 25, 2025 03:31
@swapnil-nagar swapnil-nagar requested a review from Copilot June 25, 2025 03:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.

@Copilot Copilot AI changed the title [WIP] Use alternatives to formData from undici for processing form data Replace deprecated undici formData() method with @fastify/busboy implementation Jun 25, 2025
@Copilot Copilot AI requested a review from swapnil-nagar June 25, 2025 03:38
Copilot finished work on behalf of swapnil-nagar June 25, 2025 03:38
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.

Use alternatives to formData from undici for processing form data
2 participants