msw icon indicating copy to clipboard operation
msw copied to clipboard

Bypassed POST request yields invalid on-the-wire HTTP request (missing starting-line) with form-data file attachment

Open thecopy opened this issue 1 year ago • 1 comments

Prerequisites

Environment check

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

Node.js version

v20.18.0

Reproduction repository

https://github.com/thecopy/msw-bug

Reproduction steps

  1. npm install
  2. node index.cjs

If you comment line mwsServer.listen(...), it works. OR If you remove the attached file, it works.

If i downgrade to [email protected] it works.

Current behavior

Invalid HTTP request is generated

HTTP request:

Host: localhost:51244
Accept-Encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------506525977784982220171228
Content-Length: 3693
Connection: close

Resulting in error from node:http:

[Error: Parse Error: Invalid method encountered] {
  bytesParsed: 3,
  code: 'HPE_INVALID_METHOD',
  reason: 'Invalid method encountered',
  rawPacket: <Buffer 0d 0a 48 6f 73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 35 31 32 34 34 0d 0a 41 63 63 65 70 74 2d 45 6e 63 6f 64 69 6e 67 3a 20 67 7a 69 70 2c 20 64 65 ... 143 more bytes>
}

Expected behavior

HTTP request:

POST /test HTTP/1.1 <------------- THIS IS MISSING
Host: localhost:51244
Accept-Encoding: gzip, deflate
content-type: multipart/form-data; boundary=--------------------------506525977784982220171228
Content-Length: 3693
Connection: close

thecopy avatar Oct 10 '24 07:10 thecopy

Without file attachment With file attachment
image image

thecopy avatar Oct 10 '24 07:10 thecopy

@thecopy, thanks for reporting this. I've translated your reproduction repo to a test case and fixed the issue in @mswjs/interceptors. Will propagate to MSW soon.

kettanaito avatar Nov 06 '24 12:11 kettanaito