Skip to content

Commit 04e47ba

Browse files
divybotlittledivy
andauthored
fix(ext/node): expose Http2Session and nghttp2ErrorString on http2 internalBinding (#33732)
Enables `test-http2-client-onconnect-errors` in node_compat suite. Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
1 parent df8d21c commit 04e47ba

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

ext/node/polyfills/http2.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
streamBaseState,
7575
} from "ext:deno_node/internal_binding/stream_wrap.ts";
7676
import {
77+
Http2Session as BindingHttp2Session,
7778
Http2Stream as BindingHttp2Stream,
7879
} from "ext:deno_node/internal_binding/http2.ts";
7980
import { EventEmitter } from "node:events";
@@ -965,13 +966,17 @@ function requestOnConnect(headersList, options) {
965966

966967
// `ret` will be either the reserved stream ID (if positive)
967968
// or an error code (if negative)
968-
const ret = session[kHandle].request(
969-
headersList[0],
970-
headersList[1],
971-
streamOptions,
972-
options.parent | 0,
973-
options.weight | 0,
974-
!!options.exclusive,
969+
const ret = ReflectApply(
970+
BindingHttp2Session.prototype.request,
971+
session[kHandle],
972+
[
973+
headersList[0],
974+
headersList[1],
975+
streamOptions,
976+
options.parent | 0,
977+
options.weight | 0,
978+
!!options.exclusive,
979+
],
975980
);
976981

977982
// In an error condition, one of three possible response codes will be

ext/node/polyfills/internal_binding/http2.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ class Http2Stream {
1818
}
1919
}
2020

21+
class Http2Session {
22+
request(
23+
this: {
24+
request(
25+
headers: string,
26+
count: number,
27+
options: number,
28+
parent: number,
29+
weight: number,
30+
exclusive: boolean,
31+
): unknown;
32+
},
33+
headers: string,
34+
count: number,
35+
options: number,
36+
parent: number,
37+
weight: number,
38+
exclusive: boolean,
39+
): unknown {
40+
// Tests replace this prototype method; otherwise `this` is the native
41+
// handle, so dispatch falls through to the handle's own `request` op.
42+
return this.request(headers, count, options, parent, weight, exclusive);
43+
}
44+
}
45+
2146
function nghttp2ErrorString(integerCode: number) {
2247
return op_http2_error_string(integerCode);
2348
}

tests/node_compat/config.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,7 @@
16171617
"parallel/test-http2-clean-output.js": {},
16181618
"parallel/test-http2-client-connection-tunnelling.js": {},
16191619
"parallel/test-http2-client-destroy.js": {},
1620+
"parallel/test-http2-client-onconnect-errors.js": {},
16201621
"parallel/test-http2-client-port-80.js": {},
16211622
"parallel/test-http2-client-priority-before-connect.js": {},
16221623
"parallel/test-http2-client-promisify-connect-error.js": {},

0 commit comments

Comments
 (0)