-
Notifications
You must be signed in to change notification settings - Fork 546
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
feat: add http2 #720
feat: add http2 #720
Conversation
@mcollina as noted in the "Features" section of this pull request, we have two options.
We have only discussed the prior, so I'd like to take this opportunity to ask what the desired approach is before I begin. |
Codecov Report
@@ Coverage Diff @@
## main #720 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 1854 1854
=========================================
Hits 1854 1854 Continue to review full report at Codecov.
|
I don't think you need to develop a new |
I would just focus on creating a The hardest part is figuring out is the upgrade to HTTP/2 |
@mcollina This is pretty easy. All we need to do is just create a TLS connection and check the ALPN protocol. Something like: if (socket.alpnProtocol === 'h2') {
const session = http2.connect(origin, {
createConnection: () => socket
});
...
}
const client = new HttpClient(socket);
... |
That depends - the protocol is different depending on whether the desired connection is HTTPS or HTTP. As I mentioned, if TLS is present, you must use ALPN first. If not, you have to follow the standard HTTP Upgrade procedure. |
I think http2 should always be https? I don’t think we need to support the non TLS case for http2. |
That doesn't sit right with me. We shouldn't just ignore usages that are part of the specification itself for our own convenience, especially when it'll likely result in someone filing an issue later on. |
It's needed and used within microservices networks. |
I thought the same - browsers don't [support h2c].
I believe there are better solutions in these cases. Anyway they can just use the native |
Thank you. That's not quite the same as dropping an entire protocol. Although, I do trust and hope there are technical reasons for not following those parts too, beyond merely convenience of implementation.
Not yet. Most of the point of HTTP/2 was for browsers so It most likely will.
You could also argue that you could use the native |
I don't think
That's not quite the same as I'd prefer if |
FYI: Google Cloud Run supports h2c https://cloud.google.com/run/docs/configuring/http2. My take is that h2c support might be really handy. |
h2c is super useful for debugging tricky protocol issues using Wireshark, etc. |
Summary
Decision: To start with, I will be implementing the methods on a new
Decision:
Decision: As aforementioned, TLS support is part of the natural protocol of any HTTP/2 upgrade. It is an extension, not a separate method, and therefore both can be achieved simultaneously. |
Does anyone here know about polyfill support for |
Just use that and we'll polyfill later. Anyway, @panva do you know what's the best polyfill for that? |
@mcollina you can take inspiration from https://github.com/panva/jose/blob/main/src/runtime/node/base64url.ts |
The api methods are assigned to the prototypes in index.js. See, https://github.com/nodejs/undici/blob/main/index.js#L15. |
Interesting, thank you, that didn't display in GitHub search weirdly. Peculiar approach, but it makes life easier actually since I can avoid a circular dependency between the client and its http2 variant when they merge. |
Can we safely implement a wider |
5d7e3e4
to
d684ce0
Compare
Just to double-check and give a life signal 😅 |
Yes.
I think this was extensively covered in this PR. To be honest, having something that worked would be a good starting point. My suggestion is to start by creating a HTTP2Client. |
I think @szmarczak is already working on a new PR adding HTTP/2. Happy to take a look at if so, really interested in how does it works 🙂 |
I think @szmarczak is already working on a new PR adding HTTP/2. Happy
to take a look at if so, really interested in how does it works 🙂
As far as I've seen, using node core `http2`, despite our former
discussions. Either way, hopefully it'll turn out well.
|
a2ad318
to
904e045
Compare
dcb1656
to
af20fdc
Compare
Is there any work being done on this? |
Not to my knowledge, feel free to take over. |
I'll try to revisit it as soon as I have time, but I think @szmarczak has some progress already |
Superseded by #2061 |
This relates to...
Rationale
HTTP/2 support is one of the few things currently missing from Undici
that sets it behind native Node
http
.Changes
This pull request is a work in progress. There are no changes just
yet. The plan, however, as discussed in the original issue, is to
implement HTTP/2 support around a
Dispatcher
instance forPool
,Client
andAgent
.Implementation can work in one of the following ways (see RFC7540 and
RFC8740):
using the Upgrade header (
h2c
for http URI schema,h2
for TLS) andHTTP2-Settings header
will be accompanied by a response to prior requests and the connection can
upgrade to HTTP/2. If the response is normal, exempli gratia, a HTTP 200 OK,
the client must not switch to HTTP/2.
As for HTTPS, TLS negotiation must occur prior to any upgrade to HTTP/2.
Features
HTTP/2 variants of
Pool
,Client
andAgent
. Alternatively, an option in theaforementioned classes that causes them to attempt a HTTP/2 upgrade.
Bug Fixes
N/A.
Breaking Changes and Deprecations
N/A.
Status
KEY: S = Skipped, x = complete