-
-
Notifications
You must be signed in to change notification settings - Fork 18
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(adapter-node): add http2 support #185
base: main
Are you sure you want to change the base?
Conversation
"editor.formatOnSave": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this out of convenience.
type GenericResponse = { | ||
write(chunk: Uint8Array): boolean; | ||
once(event: "drain", listener: () => void): void; | ||
once(event: "error", listener: (err: unknown) => void): void; | ||
off(event: "drain", listener: () => void): void; | ||
off(event: "error", listener: (err: unknown) => void): void; | ||
}; | ||
|
||
async function writeAndAwait( | ||
chunk: Uint8Array, | ||
res: ServerResponse, | ||
res: GenericResponse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed because write
methods of http.ServerResponse
and http2.Http2ServerResponse
are not compatible according to the type-checker, even though they are when called without a callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is used by functions that want to support both node:http
and node:http2
. For example, createRequestAdapter
and sendResponse
use these types.
Looks great! |
export interface DecoratedRequest extends Omit<IncomingMessage, "socket"> { | ||
ip?: string; | ||
protocol?: string; | ||
socket: PossiblyEncryptedSocket; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property was non-optional, but I saw another DecoratedRequest
type in src/request.ts
had it set as optional. Which one is right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not optional, req.socket
is always defined.
What I'm trying to achieve is that there's a badly documented req.socket.encrypted
property that only exists when using node:https
. The adapter uses it to infer the protocol (https or http) part of the URL when origin isn't manually set and trustProxy
is false. (req.protocol
is a non-standard Express property, useful when embedding a Hattip app into an Express app as a middleware).
I think the one in src/request.ts
is just an error on my part.
e4d5cdd
to
ca02ba9
Compare
ca02ba9
to
f22ea93
Compare
The test will fail since Node only supports HTTP/2 over TLS. Also, it appears that native fetch in Node does not support HTTP/2 yet? nodejs/undici#2750 I don't know when I'll be able to investigate a solution. |
Added support for
node:http2
. I decided not to create a newadapter-node-http2
package, since they share a lot of code.Same exact API as
@hattip/adapter-node
HTTP/1.1 API.Other entry points include:
@hattip/adapter-node/http2/native-fetch
@hattip/adapter-node/http2/whatwg-node
No tests have been added yet.