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

fix(ext/node): pass alpnProtocols to Deno.startTls #22512

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ext/node/polyfills/_tls_wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class TLSSocket extends net.Socket {
secureConnecting: boolean;
_SNICallback: any;
servername: string | null;
alpnProtocol: any;
alpnProtocols: string[] | null;
authorized: boolean;
authorizationError: any;
[kRes]: any;
Expand Down Expand Up @@ -96,6 +96,7 @@ export class TLSSocket extends net.Socket {
caCerts = [new TextDecoder().decode(caCerts)];
}
tlsOptions.caCerts = caCerts;
tlsOptions.alpnProtocols = ["h2", "http/1.1"];

super({
handle: _wrapHandle(tlsOptions, socket),
Expand All @@ -113,7 +114,7 @@ export class TLSSocket extends net.Socket {
this.secureConnecting = true;
this._SNICallback = null;
this.servername = null;
this.alpnProtocol = null;
this.alpnProtocols = tlsOptions.alpnProtocols;
this.authorized = false;
this.authorizationError = null;
this[kRes] = null;
Expand Down
9 changes: 5 additions & 4 deletions ext/node/polyfills/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ export class Http2Session extends EventEmitter {
}

goaway(
_code: number,
_lastStreamID: number,
_opaqueData: Buffer | TypedArray | DataView,
code?: number,
lastStreamID?: number,
opaqueData?: Buffer | TypedArray | DataView,
) {
warnNotImplemented("Http2Session.goaway");
// TODO(satyarohith): create goaway op and pass the args
debugHttp2(">>> goaway - ignored args", code, lastStreamID, opaqueData);
Comment on lines +217 to +218
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gonna be hard - last time I tried it, h2/hyper didn't allow to explicitly send goaway frame :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I found that frame module is public under unstable feature flag but I need to check whether send_data() on SendStream allows us to send single frames (it does allow sending data frames but not sure about goaway).

if (this[kDenoConnRid]) {
core.tryClose(this[kDenoConnRid]);
}
Expand Down
31 changes: 30 additions & 1 deletion tests/unit_node/http2_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as http2 from "node:http2";
import * as net from "node:net";
import { assertEquals } from "@std/assert/mod.ts";
import { assert, assertEquals } from "@std/assert/mod.ts";

for (const url of ["http://127.0.0.1:4246", "https://127.0.0.1:4247"]) {
Deno.test(`[node/http2 client] ${url}`, {
Expand Down Expand Up @@ -136,3 +136,32 @@ Deno.test("[node/http2 server]", { sanitizeOps: false }, async () => {

await new Promise((resolve) => server.close(resolve));
});

Deno.test("[node/http2 client GET https://www.example.com]", async () => {
const clientSession = http2.connect("https://www.example.com");
const req = clientSession.request({
":method": "GET",
":path": "/",
});
let headers = {};
let status: number | undefined = 0;
let chunk = new Uint8Array();
const endPromise = Promise.withResolvers<void>();
req.on("response", (h) => {
status = h[":status"];
headers = h;
});
req.on("data", (c) => {
chunk = c;
});
req.on("end", () => {
clientSession.close();
req.close();
endPromise.resolve();
});
req.end();
await endPromise.promise;
assert(Object.keys(headers).length > 0);
assertEquals(status, 200);
assert(chunk.length > 0);
});