-
-
Notifications
You must be signed in to change notification settings - Fork 941
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
HTTP2 support #167
Comments
Support for it can be detected with this: https://github.com/stefanjudis/is-http2 |
As far as I know, the http2 module is not well maintained, you should use spdy instead. And I don't believe it is needed to detect HTTP2, simply use spdy to make the request and the protocol will be properly negotiated. @sindresorhus, @floatdrop you could make this optional by using a |
That's nice to know :) |
I think I've read somewhere that spdy is the HTTP2 implementation that will be merged into Node in the future. |
It should, but it seems that is going to take time since there are too many arguing for it/against it. The |
Why not just use the agent option? got('google.com', {agent: require('spdy').createAgent()}); |
That's indeed the easiest approach, but it still requires to specify the agent everywhere while the inclusion in got make it transparent… |
Create a |
I guess we could try/catch it, but let's see what @floatdrop says. |
@sindresorhus I don't have clear opinion on this right now – there are many things to consider:
But I like idea and have service on sight, that could be ported to HTTP2 to test this. What I'm certain about - this should be major release 😄 I will take deep look into it on weekend. |
@floatdrop To be clear how it would work. Node.js module resolution reads dependencies recursively upwards in the dependency tree. That means we can try/catch trying to require |
Relevant: nodejs/node-eps#38 |
Seems like this is going to merge soon: nodejs/node#14239 |
I was wondering if there was any update on this now that it has made its way into Node 8? |
http/2 has now been in core for a while now. Even though the module's stability is marked as experimental, it would be worthwhile to start looking into this. |
I welcome a PR for this, but it's not something I can prioritize right now. |
Relevant |
Relevant Node.js issue about bringing HTTP2 support out of experimental: nodejs/node#19453 |
I've created an http2-client that completely mimcs the http / https native modules while supporting http2. It was very easy to integrate it with this module (and a few others) : However, it has very few lines of code, all it's behavior comes from : http2-client , got Hope it somehow helps... |
Forgot to say, it's obviously negotiates with the server the correct protocol (ALPN) to choose, https vs http2. I would be happy to contribute in any way I can. |
New version of Here's Got example for HTTP2 with ALPN negotiation (supports HTTP, HTTPS and HTTP2) 🎉 https://gist.github.com/szmarczak/59db2fa713aa7f52949d343d9cf93ff6 |
@szmarczak awesome! I still have a test on my todo list, will let you know ;) |
@szmarczak Thanks for the release! Is there a way I can modify the initial https://gist.github.com/paambaati/5e52b5bc42b2e6eebcfb55213d1853a1 |
@paambaati The problem is you are trying pass const {body: h2body} = await got('https://nghttp2.org/httpbin/headers', {
json: true,
headerTableSize: 65536,
maxConcurrentStreams: 1000,
initialWindowSize: 6291456
}); |
const http2 = require('http2-wrapper');
const {extend: gotExtend} = require('got');
const got = gotExtend({
hooks: {
beforeRequest: [
async options => {
if (options.protocol === 'https:' && !options.request) {
const {alpnProtocol, socket} = await http2.auto.resolveALPN({
...options,
resolveSocket: !options.createConnection
});
if (socket) {
options.createConnection = () => socket;
}
if (alpnProtocol === 'h2') {
options.request = http2.request;
} else {
options.session = options.socketSession;
}
}
}
]
}
}); |
@szmarczak I still feel like haven’t solved the connection caching and reuse question well. As far as I can tell we’ll still establish a new Socket for every request. I’ve tried to address this in alpn-agent and I’ll try to splice that into the example in the next couple of days. |
@pietermees You're right. It is so, because to solve szmarczak/http2-wrapper#6 |
Per the continued discussion on that thread, I think there's enough in place to provide a solution today, without changes to Node. But I'll try to prove that out with an example :) |
@szmarczak I've created a demo using Seems to work great! You can see debug output by running the script with |
@IssueHunt has funded $200.00 to this issue.
|
@pietermees I just figured out that providing Making the H1 Agent use our sockets is just too hard, IMO not worth it. I propose this:
|
@szmarczak could you explain why I'm concerned an ALPN cache might introduce some unexpected issues and behavior:
|
I mean it reuses sockets for HTTP2. But to reuse sockets for HTTP1 you need to provide another agent because the H2 agent is not compatible with H1 agent. So in total there will be two sockets. Reusing H2 sockets for H1 is a bad idea because H2 sockets must not be malformed. There are different settings for H2 and H1... Another example: imagine all seats for free sessions are taken and you've just finished your request. The session is free and it's being closed. If there's some pending H1 request it will throw an error.
Good point.
I'll look into this. |
@pietermees Thanks for the example. However, there seems to be a serious incompatibility with got implementation. Request just crashes the app on failure. Easy steps to reproduce:
|
How is the support for HTTP2? |
It's 99.99% stable, but the PR has not been merged yet due to a |
@szmarczak absolutely. It smells like no tests were done for that result. |
@leodutra You're right. I've looked it Node tests right now and it seems they do check false |
@sindresorhus has rewarded $180.00 to @szmarczak. See it on IssueHunt
|
Hi!
Can you consider adding
HTTP2
support to GOT?Currently the most used client library is this: https://github.com/molnarg/node-http2
Thank you!
IssueHunt Summary
szmarczak has been rewarded.
Backers (Total: $200.00)
Submitted pull Requests
Tips
The text was updated successfully, but these errors were encountered: