@@ -73,7 +73,6 @@ const {
73
73
kMaxResponseSize,
74
74
kHTTPConnVersion,
75
75
// HTTP2
76
- kHost,
77
76
kHTTP2SessionState,
78
77
kHTTP2BuildRequest,
79
78
kHTTP2CopyHeaders,
@@ -285,7 +284,6 @@ class Client extends DispatcherBase {
285
284
openStreams : 0 , // Keep track of them to decide whether or not unref the session
286
285
maxConcurrentStreams : maxConcurrentStreams != null ? maxConcurrentStreams : 100 // Max peerConcurrentStreams for a Node h2 server
287
286
}
288
- this [ kHost ] = `${ this [ kUrl ] . hostname } ${ this [ kUrl ] . port ? `:${ this [ kUrl ] . port } ` : '' } `
289
287
290
288
// kQueue is built up of 3 sections separated by
291
289
// the kRunningIdx and kPendingIdx indices.
@@ -395,8 +393,6 @@ class Client extends DispatcherBase {
395
393
resolve ( )
396
394
}
397
395
398
- this [ kHTTP2SessionState ] = null
399
-
400
396
if ( this [ kSocket ] ) {
401
397
util . destroy ( this [ kSocket ] . on ( 'close' , callback ) , err )
402
398
} else {
@@ -408,63 +404,6 @@ class Client extends DispatcherBase {
408
404
}
409
405
}
410
406
411
- function onHttp2SessionError ( err ) {
412
- assert ( err . code !== 'ERR_TLS_CERT_ALTNAME_INVALID' )
413
-
414
- this [ kSocket ] [ kError ] = err
415
-
416
- onError ( this [ kClient ] , err )
417
- }
418
-
419
- function onHttp2FrameError ( type , code , id ) {
420
- const err = new InformationalError ( `HTTP/2: "frameError" received - type ${ type } , code ${ code } ` )
421
-
422
- if ( id === 0 ) {
423
- this [ kSocket ] [ kError ] = err
424
- onError ( this [ kClient ] , err )
425
- }
426
- }
427
-
428
- function onHttp2SessionEnd ( ) {
429
- util . destroy ( this , new SocketError ( 'other side closed' ) )
430
- util . destroy ( this [ kSocket ] , new SocketError ( 'other side closed' ) )
431
- }
432
-
433
- function onHTTP2GoAway ( code ) {
434
- const client = this [ kClient ]
435
- const err = new InformationalError ( `HTTP/2: "GOAWAY" frame received with code ${ code } ` )
436
- client [ kSocket ] = null
437
-
438
- if ( client . destroyed ) {
439
- assert ( this [ kPending ] === 0 )
440
-
441
- // Fail entire queue.
442
- const requests = client [ kQueue ] . splice ( client [ kRunningIdx ] )
443
- for ( let i = 0 ; i < requests . length ; i ++ ) {
444
- const request = requests [ i ]
445
- errorRequest ( this , request , err )
446
- }
447
- } else if ( client [ kRunning ] > 0 ) {
448
- // Fail head of pipeline.
449
- const request = client [ kQueue ] [ client [ kRunningIdx ] ]
450
- client [ kQueue ] [ client [ kRunningIdx ] ++ ] = null
451
-
452
- errorRequest ( client , request , err )
453
- }
454
-
455
- client [ kPendingIdx ] = client [ kRunningIdx ]
456
-
457
- assert ( client [ kRunning ] === 0 )
458
-
459
- client . emit ( 'disconnect' ,
460
- client [ kUrl ] ,
461
- [ client ] ,
462
- err
463
- )
464
-
465
- resume ( client )
466
- }
467
-
468
407
const constants = require ( './llhttp/constants' )
469
408
const createRedirectInterceptor = require ( './interceptor/redirectInterceptor' )
470
409
const EMPTY_BUF = Buffer . alloc ( 0 )
@@ -1222,10 +1161,48 @@ async function connect (client) {
1222
1161
} )
1223
1162
1224
1163
client [ kHTTPConnVersion ] = 'h2'
1225
- session . on ( 'error' , onHttp2SessionError )
1226
- session . on ( 'frameError' , onHttp2FrameError )
1227
- session . on ( 'end' , onHttp2SessionEnd )
1228
- session . on ( 'goaway' , onHTTP2GoAway )
1164
+ session . on ( 'frameError' , ( type , code , id ) => {
1165
+ if ( id === 0 ) {
1166
+ const err = new InformationalError ( `HTTP/2: "frameError" received - type ${ type } , code ${ code } ` )
1167
+ util . destroy ( session , err )
1168
+ util . destroy ( socket , err )
1169
+ }
1170
+ } )
1171
+ session . on ( 'end' , ( ) => {
1172
+ const err = new SocketError ( 'other side closed' )
1173
+ util . destroy ( session , err )
1174
+ util . destroy ( socket , err )
1175
+ } )
1176
+ session . on ( 'goaway' , ( code ) => {
1177
+ const client = this [ kClient ]
1178
+ const err = new InformationalError ( `HTTP/2: "GOAWAY" frame received with code ${ code } ` )
1179
+ client [ kSocket ] = null
1180
+
1181
+ if ( client . destroyed ) {
1182
+ assert ( this [ kPending ] === 0 )
1183
+
1184
+ // Fail entire queue.
1185
+ const requests = client [ kQueue ] . splice ( client [ kRunningIdx ] )
1186
+ for ( let i = 0 ; i < requests . length ; i ++ ) {
1187
+ const request = requests [ i ]
1188
+ errorRequest ( this , request , err )
1189
+ }
1190
+ } else if ( client [ kRunning ] > 0 ) {
1191
+ // Fail head of pipeline.
1192
+ const request = client [ kQueue ] [ client [ kRunningIdx ] ]
1193
+ client [ kQueue ] [ client [ kRunningIdx ] ++ ] = null
1194
+
1195
+ errorRequest ( client , request , err )
1196
+ }
1197
+
1198
+ client [ kPendingIdx ] = client [ kRunningIdx ]
1199
+
1200
+ assert ( client [ kRunning ] === 0 )
1201
+
1202
+ client . emit ( 'disconnect' , client [ kUrl ] , [ client ] , err )
1203
+
1204
+ resume ( client )
1205
+ } )
1229
1206
session . on ( 'close' , onSocketClose )
1230
1207
session . unref ( )
1231
1208
@@ -1665,7 +1642,9 @@ function writeH2 (client, session, request) {
1665
1642
let stream
1666
1643
const h2State = client [ kHTTP2SessionState ]
1667
1644
1668
- headers [ HTTP2_HEADER_AUTHORITY ] = host || client [ kHost ]
1645
+ const { hostname, port } = client [ kUrl ]
1646
+
1647
+ headers [ HTTP2_HEADER_AUTHORITY ] = host || `${ hostname } ${ port ? `:${ port } ` : '' } `
1669
1648
headers [ HTTP2_HEADER_METHOD ] = method
1670
1649
1671
1650
try {
0 commit comments