@@ -20,10 +20,7 @@ function loadKey(keyname) {
2020function onStream ( stream , headers ) {
2121 const socket = stream . session [ kSocket ] ;
2222 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' } ) ;
2724 stream . end ( JSON . stringify ( {
2825 servername : socket . servername ,
2926 alpnProtocol : socket . alpnProtocol
@@ -33,35 +30,32 @@ function onStream(stream, headers) {
3330function verifySecureSession ( key , cert , ca , opts ) {
3431 const server = h2 . createSecureServer ( { cert, key } ) ;
3532 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 || { } ;
4235 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 ( ) ;
4541
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+ } ) ) ;
5247
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+ } ) ) ;
6559 } ) ) ;
6660}
6761
0 commit comments