msw
msw copied to clipboard
Bypassed POST request yields invalid on-the-wire HTTP request (missing starting-line) with form-data file attachment
Prerequisites
- [X] I confirm my issue is not in the opened issues
- [X] I confirm the Frequently Asked Questions didn't contain the answer to my issue
Environment check
- [X] I'm using the latest
mswversion - [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
-
npm install -
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
| Without file attachment | With file attachment |
|---|---|
@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.