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

No need to call undocumented nodejs function ServerResponse._implicitHeader #888

Closed
yunnysunny opened this issue May 4, 2022 · 3 comments · May be fixed by #908
Closed

No need to call undocumented nodejs function ServerResponse._implicitHeader #888

yunnysunny opened this issue May 4, 2022 · 3 comments · May be fixed by #908

Comments

@yunnysunny
Copy link

express-session call such code to ensure http header has been sent before writing data.
But nodejs has include such code in the ServerResponse class write function.

Another side we should consider is that http2.Http2ServerResponse does not have the property of _implicitHeader. When we start server via http2, the express-session will break.

@dougwilson
Copy link
Contributor

Hello, and thank you for your issue. Yes, the internal write function would call that, but where it is called in this module happens before the internal write function, as it overrides it. Without calling it, none of the automatic response headers will be present to inspect before the decision making this module does, as well as causes strange issues when res.end gets called twice, among other issues.

If you have a solution that uses a different method but keeps all the behavior intact, please contribute a pull request :) !

@yunnysunny
Copy link
Author

has pulled a request : #900

@Martin-Luther
Copy link

Martin-Luther commented Dec 10, 2022

I had the same issue : http2 + express-session and the latest version of express-session 1.17.3 did not help.
express-session is not the only module impacted: I saw people having the same issue with express-compression.

NB.: I am not using ExpressJS, but my framework allows me to use modules/plugins from ExpressJS

Option 1)
You don't have the time to wait for a fix, you can intercept your response and add a test inside your script right before calling res.end(...)

if (!res._implicitHeader) {
    // Hack required until `express-<plugin>` get support for http2 (express-session)
    res._implicitHeader = function(){ return; }; // Don't need, don't care
}
res.end();

This worked for me.

Option 2)
For those brave enough to fixe this issue for people like me.
Open express-session/index.js line @275

You should have something like:

if (!res._header) {
    res._implicitHeader()
}

Needs to be replaced by:

if (!res._header && res._implicitHeader) {
    res._implicitHeader()
}

This will skip the call for people using http2 or when res._implicitHeader not defined.

Let me know if it worked for you guys.

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

Successfully merging a pull request may close this issue.

3 participants