@@ -4,61 +4,47 @@ const common = require('../common');
4
4
if ( ! common . hasCrypto )
5
5
common . skip ( 'missing crypto' ) ;
6
6
7
- if ( ! common . hasMultiLocalhost ( ) )
8
- common . skip ( 'platform-specific test.' ) ;
9
-
10
7
const http2 = require ( 'http2' ) ;
11
- const assert = require ( 'assert' ) ;
12
8
const tls = require ( 'tls' ) ;
13
9
const fixtures = require ( '../common/fixtures' ) ;
14
10
15
11
const serverOptions = {
16
12
key : fixtures . readKey ( 'agent1-key.pem' ) ,
17
13
cert : fixtures . readKey ( 'agent1-cert.pem' )
18
14
} ;
19
- const server = http2 . createSecureServer ( serverOptions , ( req , res ) => {
20
- console . log ( `Connect from: ${ req . connection . remoteAddress } ` ) ;
21
- assert . strictEqual ( req . connection . remoteAddress , '127.0.0.2' ) ;
22
15
23
- req . on ( 'end' , common . mustCall ( ( ) => {
24
- res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
25
- res . end ( `You are from: ${ req . connection . remoteAddress } ` ) ;
26
- } ) ) ;
27
- req . resume ( ) ;
16
+ const server = http2 . createSecureServer ( serverOptions , ( req , res ) => {
17
+ res . end ( ) ;
28
18
} ) ;
29
19
30
20
server . listen ( 0 , '127.0.0.1' , common . mustCall ( ( ) => {
31
21
const options = {
32
22
ALPNProtocols : [ 'h2' ] ,
33
23
host : '127.0.0.1' ,
34
24
servername : 'localhost' ,
35
- localAddress : '127.0.0.2' ,
36
25
port : server . address ( ) . port ,
37
26
rejectUnauthorized : false
38
27
} ;
39
28
40
- console . log ( 'Server ready' , server . address ( ) . port ) ;
41
-
42
29
const socket = tls . connect ( options , async ( ) => {
43
-
44
- console . log ( 'TLS Connected!' ) ;
45
-
46
- setTimeout ( ( ) => {
47
-
30
+ socket . once ( 'readable' , ( ) => {
48
31
const client = http2 . connect (
49
32
'https://localhost:' + server . address ( ) . port ,
50
33
{ ...options , createConnection : ( ) => socket }
51
34
) ;
52
- const req = client . request ( {
53
- ':path' : '/'
54
- } ) ;
55
- req . on ( 'data' , ( ) => req . resume ( ) ) ;
56
- req . on ( 'end' , common . mustCall ( function ( ) {
57
- client . close ( ) ;
58
- req . close ( ) ;
59
- server . close ( ) ;
35
+
36
+ client . once ( 'remoteSettings' , common . mustCall ( ( ) => {
37
+ const req = client . request ( {
38
+ ':path' : '/'
39
+ } ) ;
40
+ req . on ( 'data' , ( ) => req . resume ( ) ) ;
41
+ req . on ( 'end' , common . mustCall ( ( ) => {
42
+ client . close ( ) ;
43
+ req . close ( ) ;
44
+ server . close ( ) ;
45
+ } ) ) ;
46
+ req . end ( ) ;
60
47
} ) ) ;
61
- req . end ( ) ;
62
- } , 1000 ) ;
48
+ } ) ;
63
49
} ) ;
64
50
} ) ) ;
0 commit comments