Skip to content

Axios FormData upload broken in v2 #1835

@pschyma

Description

@pschyma

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v18.18.2

Reproduction repository

https://github.com/pschyma/msw-examples/tree/axios-formdata-reproducer

Reproduction steps

cd examples/with-vitest
npm install
npm test

Current behavior

I'm not sure where the issue is, but as msw v2 triggered this issue for me, I'll start here.

After updating to msw 2 FormData upload via Axios stops working due to missing boundary in Content-Type header.

Headers observed when posting data with fetch:

{
  'content-type' => {
    name: 'content-type',
    value: 'multipart/form-data; boundary=----formdata-undici-088515513855'
  }
}

Headers observed when posting data with Axios:

{
  'content-type' => {
    name: 'content-type',
    value: 'multipart/form-data'
  }
}

Expected behavior

Axios requests behave like when msw < 2 is used and provide the boundary in headers.

In previous msw version, I used parse-multipart-data to extract the boundary from request headers and for parsing the text content of that request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingscope:nodeRelated to MSW running in Node

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions