Skip to content
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

don't set header when respond=false and header sent #1044

Closed
dead-horse opened this issue Aug 18, 2017 · 3 comments
Closed

don't set header when respond=false and header sent #1044

dead-horse opened this issue Aug 18, 2017 · 3 comments

Comments

@dead-horse
Copy link
Member

many people using next.js or migrate there app from express will set respond=false, but lots of koa's middleware will set header like:

async (ctx, next) => {
    await next();
    ctx.set('foo', 'bar');
}

it will cause Can't set headers after they are sent error if we already sent response body before. Maybe we can make ctx.set() invalid when respond=false and header sent. (We can log something when NODE_ENV is develop to hint developer this unexpected behavior)

related issues:

Any thoughts?

@nordsimon
Copy link

I just saw your reference @dead-horse. From my point of view, respond.false is very useful and sometimes neccessary in specific implementations. I would go for logging a warning in develop (or via debug) module mode but still allow and fix the behaviour. Maybe add some more info what side effects respond false has ?

@nordsimon
Copy link

And yes, I see that this should actually live in koa and not in koa-session, I will close my PR in order to find a solution here

@dead-horse
Copy link
Member Author

this is already fixed in #1137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants