-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: consume undisturbed request stream as-is #39
Conversation
Use Express.js instead of HttpServer from open-draft since open-draft will automatically convert json request body to Object. With Express.js and express.raw(), everything works fine.
This will unfortunately be a breaking change. The must-need I didn't think of a way to avoid a middleware. Express.js doesn't provide any way to access the raw request body but using |
Just spent 2 hours trying to debug why calling Let me know if I can be of any help to get this merged and released. |
Co-authored-by: Benoît Burgener <benoit.burgener@gmail.com>
I think a larger default size limit is a good idea. So for @LeBenLeBen Please review these changes, wish we can merge this one. Thanks :) |
test/with-express-json.test.ts
Outdated
|
||
const app = express() | ||
|
||
app.use(express.raw({ type: '*/*' })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think if we bake in express.raw()
into createMiddleware()
itself?
Applying it to the entire server is too much anyway since people can attach handlers-based routes to an existing Express server.
In other words, having the raw body parser is a prerequisite of the middleware. So it must be defined there, next to the middleware.
Hello guys, I got this error today: Is there anything I can do to help? |
I've just created an issue to cross-reference this PR: #47 |
Still not solved. Going the Nock way. |
Any news about this issue, is a fix still in the pipeline or should this be considered abandoned? Mock server spawned with http-middleware only seems to handle json. |
@rwdevops999, @iivo-k, we did this in the meanwhile: #47 (comment) |
multipart/form-data
requests
multipart/form-data
requests
UpdateInstead of accounting for individual request content types, I'm creating a ReadableStream from whichever I'm making exception for |
Released: v0.10.2 🎉This has been released in v0.10.2! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
In current version, multipart form request will throw a parsing error.
This is because
createMiddleware()
treatreq.body
as the raw body and pass it tonew Request()
.But
req.body
is generated byexpress.json()
, which only parse requests with content-typeapplication/json
and leavereq.body
undefined for other requests (like multipart form).In the PR,
req.body
is prepared byexpress.raw({ type: '*/*' })
. It will get aBuffer
as the raw body for all the requests and pass it directly tonew Request()
. json, form, even other binary content types will be untouched by express and handled by user withRequest
API.