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

Express HTTP2 #220

Open
perryjsteward opened this issue Sep 29, 2016 · 7 comments
Open

Express HTTP2 #220

perryjsteward opened this issue Sep 29, 2016 · 7 comments

Comments

@perryjsteward
Copy link

Hi,

sorry for opening another issue on this but the past one is locked and hasnt been updated for a year. was there ever a resolution found for Express and HTTP2 module?

I'm still getting the error mentioned in previous comments.

image

@ghost
Copy link

ghost commented Sep 29, 2016

Same error here. ([email protected], [email protected], [email protected])

@waterfoul
Copy link

I just figured out what's happening (Digging through the code to find this took 2-3 hrs). The fault is actually express'. If you look at express/lib/middleware/init.js on lines 28 and 29 they are replacing the prototypes of the request and response. I don't know why but that is causing the http2 prototypes to get destroyed which is causing that error. If you fix the request's prototype you actually see similar issues with the response object.

@waterfoul
Copy link

waterfoul commented Oct 20, 2016

More Info. That behavior has been there since express 3.0.0... Still digging into why
Update: I can't seem to figure out why they did that but express doesn't work without it......

@waterfoul
Copy link

It appears that there has been some discussion going on in the express side
expressjs/express#2761

@waterfoul
Copy link

adding

express.request.__proto__ = http2.IncomingMessage.prototype;
express.response.__proto__ = http2.ServerResponse.prototype;

per one of the express post suggestions seems to work around the issue for now

@Jashepp
Copy link

Jashepp commented Nov 13, 2016

As the above code does work nicely, it does stop HTTP/1.x requests from working if the http server is used with express too (since the prototype is now changed to http2's).
I have made a npm module which creates new instances of express's request and response objects, and does the above prototype change only for http2 requests (via a middleware).
https://www.npmjs.com/package/express-http2-workaround
More explanation of how it works is in the package's readme.
It works with the latest http2 and express packages.
I hope this helps :)

@ghost
Copy link

ghost commented Dec 14, 2016

I will try @waterfoul and @unchosen solutions when I have some time this week. Thank you guys

@ghost ghost mentioned this issue Dec 17, 2016
zaknuces added a commit to zaknuces/oz-vox-server that referenced this issue Mar 31, 2017
Add workaround for http/1 fallback.
Reference: molnarg/node-http2#220
Add logging support
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

3 participants