Skip to content
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

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

Closed
4 tasks done
thecopy opened this issue Oct 10, 2024 · 2 comments · Fixed by mswjs/interceptors#674
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@thecopy
Copy link

thecopy commented Oct 10, 2024

Prerequisites

Environment check

  • I'm using the latest msw version
  • 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 thecopy added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Oct 10, 2024
@thecopy
Copy link
Author

thecopy commented Oct 10, 2024

Without file attachment With file attachment
image image

@kettanaito
Copy link
Member

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

@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
2 participants