@@ -1228,12 +1228,6 @@ class Http2Session extends EventEmitter {
12281228 constructor ( type , options , socket ) {
12291229 super ( ) ;
12301230
1231- if ( ! socket . _handle || ! socket . _handle . isStreamBase ) {
1232- socket = new JSStreamSocket ( socket ) ;
1233- }
1234- socket . on ( 'error' , socketOnError ) ;
1235- socket . on ( 'close' , socketOnClose ) ;
1236-
12371231 // No validation is performed on the input parameters because this
12381232 // constructor is not exported directly for users.
12391233
@@ -1245,6 +1239,12 @@ class Http2Session extends EventEmitter {
12451239
12461240 socket [ kSession ] = this ;
12471241
1242+ if ( ! socket . _handle || ! socket . _handle . isStreamBase ) {
1243+ socket = new JSStreamSocket ( socket ) ;
1244+ }
1245+ socket . on ( 'error' , socketOnError ) ;
1246+ socket . on ( 'close' , socketOnClose ) ;
1247+
12481248 this [ kState ] = {
12491249 destroyCode : NGHTTP2_NO_ERROR ,
12501250 flags : SESSION_FLAGS_PENDING ,
@@ -1644,7 +1644,7 @@ class ServerHttp2Session extends Http2Session {
16441644 // not be an issue in practice. Additionally, the 'priority' event on
16451645 // server instances (or any other object) is fully undocumented.
16461646 this [ kNativeFields ] [ kSessionPriorityListenerCount ] =
1647- server . listenerCount ( 'priority' ) ;
1647+ server ? server . listenerCount ( 'priority' ) : 0 ;
16481648 }
16491649
16501650 get server ( ) {
@@ -3435,6 +3435,11 @@ function getUnpackedSettings(buf, options = kEmptyObject) {
34353435 return settings ;
34363436}
34373437
3438+ function performServerHandshake ( socket , options = { } ) {
3439+ options = initializeOptions ( options ) ;
3440+ return new ServerHttp2Session ( options , socket , undefined ) ;
3441+ }
3442+
34383443binding . setCallbackFunctions (
34393444 onSessionInternalError ,
34403445 onPriority ,
@@ -3458,6 +3463,7 @@ module.exports = {
34583463 getDefaultSettings,
34593464 getPackedSettings,
34603465 getUnpackedSettings,
3466+ performServerHandshake,
34613467 sensitiveHeaders : kSensitiveHeaders ,
34623468 Http2Session,
34633469 Http2Stream,
0 commit comments