res.end should finish response#102
Closed
mctep wants to merge 2 commits into
Closed
Conversation
Contributor
|
This may be reasonable, but your change has some edge cases. I can fix them and get something in this week. |
Contributor
|
In the meantime, you should change your code, as it's currently broken. Your code should be checking http://nodejs.org/api/http.html#http_response_headerssent (res.headersSent) before setting headers, because res.finished is false even when you're not allowed to set headers any more, regardless of this module. This module just brought that bug in your code to light. |
Author
|
Oh, yes. You are absolutely right. Thank you so much. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello. Thanks for your job.
I have some code in express:
In some places I rely on the
res.finishedto find out whether the response has finished. And if it has not, I send the default result.But the code above throws the
Error('Can't set headers after they are sent.')because the originalreq.endis called asynchronously, and it doesn't set thereq.finishedastrueat the right time. And without using session this code works as expected.My PR resolves this problem, and I think it looks like hack. But I worked out nothing better.