|
| 1 | +'use strict'; |
| 2 | +constcommon=require('../common'); |
| 3 | +constassert=require('assert'); |
| 4 | + |
| 5 | +if(!common.hasCrypto) |
| 6 | +common.skip('missing crypto'); |
| 7 | + |
| 8 | +consthttp2=require('http2'); |
| 9 | +constnet=require('net'); |
| 10 | + |
| 11 | +const{ |
| 12 | +HTTP2_HEADER_PATH, |
| 13 | +}=http2.constants; |
| 14 | + |
| 15 | +// Create a normal session, as a control case |
| 16 | +functionnormalSession(cb){ |
| 17 | +http2.connect('https://google.com',(clientSession)=>{ |
| 18 | +leterror=null; |
| 19 | +constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'}); |
| 20 | +req.on('error',(err)=>{ |
| 21 | +error=err; |
| 22 | +}); |
| 23 | +req.on('response',(_headers)=>{ |
| 24 | +req.on('data',(_chunk)=>{}); |
| 25 | +req.on('end',()=>{ |
| 26 | +clientSession.close(); |
| 27 | +returncb(error); |
| 28 | +}); |
| 29 | +}); |
| 30 | +}); |
| 31 | +} |
| 32 | +normalSession(common.mustCall(function(err){ |
| 33 | +assert.ifError(err); |
| 34 | +})); |
| 35 | + |
| 36 | +// Create a session using a socket that has not yet finished connecting |
| 37 | +functionsocketNotFinished(done){ |
| 38 | +constsocket2=net.connect(443,'google.com'); |
| 39 | +http2.connect('https://google.com',{ socket2 },(clientSession)=>{ |
| 40 | +leterror=null; |
| 41 | +constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'}); |
| 42 | +req.on('error',(err)=>{ |
| 43 | +error=err; |
| 44 | +}); |
| 45 | +req.on('response',(_headers)=>{ |
| 46 | +req.on('data',(_chunk)=>{}); |
| 47 | +req.on('end',()=>{ |
| 48 | +clientSession.close(); |
| 49 | +socket2.destroy(); |
| 50 | +returndone(error); |
| 51 | +}); |
| 52 | +}); |
| 53 | +}); |
| 54 | +} |
| 55 | +socketNotFinished(common.mustCall(function(err){ |
| 56 | +assert.ifError(err); |
| 57 | +})); |
| 58 | + |
| 59 | +// Create a session using a socket that has finished connecting |
| 60 | +functionsocketFinished(done){ |
| 61 | +constsocket=net.connect(443,'google.com',()=>{ |
| 62 | +http2.connect('https://google.com',{ socket },(clientSession)=>{ |
| 63 | +leterror=null; |
| 64 | +constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'}); |
| 65 | +req.on('error',(err)=>{ |
| 66 | +error=err; |
| 67 | +}); |
| 68 | +req.on('response',(_headers)=>{ |
| 69 | +req.on('data',(_chunk)=>{}); |
| 70 | +req.on('end',()=>{ |
| 71 | +clientSession.close(); |
| 72 | +returndone(error); |
| 73 | +}); |
| 74 | +}); |
| 75 | +}); |
| 76 | +}); |
| 77 | +} |
| 78 | +socketFinished(common.mustCall(function(err){ |
| 79 | +assert.ifError(err); |
| 80 | +})); |
0 commit comments