-
Notifications
You must be signed in to change notification settings - Fork 397
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
Get and Head requests #114
Comments
I think you'll have same issue with express: const e = express();
e.head("/test", function(req, res, next) {
console.log("head");
next();
});
e.get("/test", function(req, res, next) {
console.log("get");
res.send("");
next();
});
e.listen(3000); I just run this code and when I do head request to |
This is the express code I tried, |
but you didn't call |
But why call |
Was it a CORS request? Because then this is the expected behaviour. Browsers will send a Check the |
@NoNameProvided My understanding was that |
no, not response-send related things. If we remove next call middleware executed after controller actions wont work. For example you want simple logging. If you to log result of execution (route, it took x seconds to execute this route) you need to do it after action execution in the middleware. Without calling |
So is it not possible to replicate this behavior of express
when this code without the |
But you have actions and middlewares stored in separate arrays. So you can just call the first after middleware after handling action result instead of calling next and rely on express middlewares stack. |
Not sure if it is correct way of doing things |
It's really bad that the So to make the feature |
Okay, if you think so, then lets remove this functionality. Can you please do that? |
Sure, I will take a look at this when I will have some free time. I had similar issue - I got |
I'm facing the same issue as mentioned by @19majkel94 in the comment above. I'm currently working round it by checking that the value of the Are there any best practices for handling this usecase? |
Stale issue message |
I think the clear workaround for this is to return the response object itself. @Controller("/test")
export default class TestController {
@Head()
head(@Res() resp:any){
console.log("head");
resp.send();
return resp;
}
@Get()
get(@Res() resp:any){
console.log("get");
resp.send("Get");
return resp;
}
} With this I don't see the fall through logs or errors. |
When the Get and Head requests are provided with the same paths, both the functions corresponding to the path are getting executed.
The test code that I tried was:
If I give a GET request to the above code, both head and get are getting logged to the console.
Even if I give a head request, the Get request function is also getting called and the error:
Can't set headers after they are sent is being encountered
The text was updated successfully, but these errors were encountered: