|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +constcommon=require('../common'); |
| 4 | +constfixtures=require('../common/fixtures'); |
| 5 | +if(!common.hasCrypto) |
| 6 | +common.skip('missing crypto'); |
| 7 | +consthttp2=require('http2'); |
| 8 | +constassert=require('assert'); |
| 9 | +constfs=require('fs'); |
| 10 | + |
| 11 | +const{ |
| 12 | +HTTP2_HEADER_CONTENT_TYPE, |
| 13 | +HTTP2_HEADER_CONTENT_LENGTH |
| 14 | +}=http2.constants; |
| 15 | + |
| 16 | +constfname=fixtures.path('elipses.txt'); |
| 17 | +constdata=fs.readFileSync(fname); |
| 18 | +conststat=fs.statSync(fname); |
| 19 | +fs.promises.open(fname,'r').then(common.mustCall((fileHandle)=>{ |
| 20 | +constserver=http2.createServer(); |
| 21 | +server.on('stream',(stream)=>{ |
| 22 | +stream.respondWithFD(fileHandle,{ |
| 23 | +[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain', |
| 24 | +[HTTP2_HEADER_CONTENT_LENGTH]: stat.size, |
| 25 | +}); |
| 26 | +}); |
| 27 | +server.on('close',common.mustCall(()=>fileHandle.close())); |
| 28 | +server.listen(0,common.mustCall(()=>{ |
| 29 | + |
| 30 | +constclient=http2.connect(`http://localhost:${server.address().port}`); |
| 31 | +constreq=client.request(); |
| 32 | + |
| 33 | +req.on('response',common.mustCall((headers)=>{ |
| 34 | +assert.strictEqual(headers[HTTP2_HEADER_CONTENT_TYPE],'text/plain'); |
| 35 | +assert.strictEqual(+headers[HTTP2_HEADER_CONTENT_LENGTH],data.length); |
| 36 | +})); |
| 37 | +req.setEncoding('utf8'); |
| 38 | +letcheck=''; |
| 39 | +req.on('data',(chunk)=>check+=chunk); |
| 40 | +req.on('end',common.mustCall(()=>{ |
| 41 | +assert.strictEqual(check,data.toString('utf8')); |
| 42 | +client.close(); |
| 43 | +server.close(); |
| 44 | +})); |
| 45 | +req.end(); |
| 46 | +})); |
| 47 | +})); |
0 commit comments