Skip to content

Commit

Permalink
fix(ext/node): pass alpnProtocols to Deno.startTls (#22512)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyarohith authored Feb 21, 2024
1 parent c75c9a0 commit 061ee9d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
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);
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);
});

0 comments on commit 061ee9d

Please sign in to comment.