@@ -20,10 +20,7 @@ function loadKey(keyname) {
20
20
function onStream ( stream , headers ) {
21
21
const socket = stream . session [ kSocket ] ;
22
22
assert ( headers [ ':authority' ] . startsWith ( socket . servername ) ) ;
23
- stream . respond ( {
24
- 'content-type' : 'text/html' ,
25
- ':status' : 200
26
- } ) ;
23
+ stream . respond ( { 'content-type' : 'application/json' } ) ;
27
24
stream . end ( JSON . stringify ( {
28
25
servername : socket . servername ,
29
26
alpnProtocol : socket . alpnProtocol
@@ -33,35 +30,32 @@ function onStream(stream, headers) {
33
30
function verifySecureSession ( key , cert , ca , opts ) {
34
31
const server = h2 . createSecureServer ( { cert, key } ) ;
35
32
server . on ( 'stream' , common . mustCall ( onStream ) ) ;
36
- server . listen ( 0 ) ;
37
- server . on ( 'listening' , common . mustCall ( function ( ) {
38
- const headers = { ':path' : '/' } ;
39
- if ( ! opts ) {
40
- opts = { } ;
41
- }
33
+ server . listen ( 0 , common . mustCall ( ( ) => {
34
+ opts = opts || { } ;
42
35
opts . secureContext = tls . createSecureContext ( { ca } ) ;
43
- const client = h2 . connect ( `https://localhost:${ this . address ( ) . port } ` , opts , function ( ) {
44
- const req = client . request ( headers ) ;
36
+ const client = h2 . connect ( `https://localhost:${ server . address ( ) . port } ` ,
37
+ opts ) ;
38
+ // Verify that a 'secureConnect' listener is attached
39
+ assert . strictEqual ( client . socket . listenerCount ( 'secureConnect' ) , 1 ) ;
40
+ const req = client . request ( ) ;
45
41
46
- req . on ( 'response' , common . mustCall ( function ( headers ) {
47
- assert . strictEqual ( headers [ ':status' ] , 200 , 'status code is set' ) ;
48
- assert . strictEqual ( headers [ 'content-type' ] , 'text/html' ,
49
- 'content type is set' ) ;
50
- assert ( headers [ 'date' ] , 'there is a date' ) ;
51
- } ) ) ;
42
+ req . on ( 'response' , common . mustCall ( ( headers ) => {
43
+ assert . strictEqual ( headers [ ':status' ] , 200 ) ;
44
+ assert . strictEqual ( headers [ 'content-type' ] , 'application/json' ) ;
45
+ assert ( headers [ 'date' ] ) ;
46
+ } ) ) ;
52
47
53
- let data = '' ;
54
- req . setEncoding ( 'utf8' ) ;
55
- req . on ( 'data' , ( d ) => data += d ) ;
56
- req . on ( 'end' , common . mustCall ( ( ) => {
57
- const jsonData = JSON . parse ( data ) ;
58
- assert . strictEqual ( jsonData . servername , opts . servername || 'localhost' ) ;
59
- assert . strictEqual ( jsonData . alpnProtocol , 'h2' ) ;
60
- server . close ( ) ;
61
- client [ kSocket ] . destroy ( ) ;
62
- } ) ) ;
63
- req . end ( ) ;
64
- } ) ;
48
+ let data = '' ;
49
+ req . setEncoding ( 'utf8' ) ;
50
+ req . on ( 'data' , ( d ) => data += d ) ;
51
+ req . on ( 'end' , common . mustCall ( ( ) => {
52
+ const jsonData = JSON . parse ( data ) ;
53
+ assert . strictEqual ( jsonData . servername ,
54
+ opts . servername || 'localhost' ) ;
55
+ assert . strictEqual ( jsonData . alpnProtocol , 'h2' ) ;
56
+ server . close ( ) ;
57
+ client [ kSocket ] . destroy ( ) ;
58
+ } ) ) ;
65
59
} ) ) ;
66
60
}
67
61
0 commit comments