BackendStack21 / restana

Restana is a lightweight and fast Node.js framework for building RESTful APIs.
MIT License
467 stars 27 forks source link

Make sure res.send does not override res.statusCode #96

Closed schamberg97 closed 4 years ago

schamberg97 commented 4 years ago

Consider this piece of code:

service.get('/route/', async (req,res)=> {
     res.statusCode = 250; // random 200-range non-existent code
     res.send('something')
})

Unfortunately, res.send will override the status code and use 200 as a default. This may be a problem with legacy applications which do not pass the status code directly to res.send

While this is not a critical issue per se, since res.send could always be overridden through middleware, I think it is more correct to do this in restana package itself, especially since res.statusCode is 200 by default anyways

jkyberneees commented 4 years ago

Thanks @schamberg97 for catching this issue and also providing a fix. 👏