You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This problem arises in v0.10.2, v0.10.1 worked without issue. Once a PUT or POST handler has been added the body has been read and cannot be read by any other middleware anymore. This is similar to what the express bodyParser middleware does but that would place the body inside the req object to be used but that's not the case here.
Simple testcase:
importexpressfrom'express';import{createMiddleware}from'@mswjs/http-middleware';import*asmswfrom'msw';constapp=express();app.use(createMiddleware([msw.http.post('something',function(){returnnewResponse(JSON.stringify({foo: 123}),{headers: {'Content-Type': 'application/json',},});}),]));app.use((req,res)=>{console.assert(req.readable===true);console.assert(req.readableDidRead===false);console.assert(req.readableEnded===false);res.sendStatus(200);});app.listen(9090,()=>console.log('Ready at http://localhost:9090'));
Test by makeing a POST request to http://localhost:9090, path doesn't have to be /something
The assertions succeed on 0.10.1 and fail on 0.10.2. They do succeed if there are only GET handlers passed to createMiddleware.
The text was updated successfully, but these errors were encountered:
editedredx
changed the title
Body stream is alredy complete and cannot be read after using http-middleware
Body stream is already complete and cannot be read after using http-middleware
Oct 31, 2024
Hi,
This problem arises in v0.10.2, v0.10.1 worked without issue. Once a PUT or POST handler has been added the body has been read and cannot be read by any other middleware anymore. This is similar to what the express bodyParser middleware does but that would place the body inside the req object to be used but that's not the case here.
Simple testcase:
Test by makeing a POST request to http://localhost:9090, path doesn't have to be /something
The assertions succeed on 0.10.1 and fail on 0.10.2. They do succeed if there are only GET handlers passed to createMiddleware.
The text was updated successfully, but these errors were encountered: