1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const fixtures = require('../common/fixtures'); 7const http2 = require('http2'); 8const assert = require('assert'); 9const fs = require('fs'); 10 11const { 12 HTTP2_HEADER_CONTENT_TYPE, 13 HTTP2_HEADER_CONTENT_LENGTH, 14 HTTP2_HEADER_LAST_MODIFIED 15} = http2.constants; 16 17const fname = fixtures.path('printA.js'); 18const data = fs.readFileSync(fname); 19const stat = fs.statSync(fname); 20 21const server = http2.createServer(); 22server.on('stream', (stream) => { 23 stream.respondWithFile(fname, { 24 [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain' 25 }, { 26 statCheck: common.mustCall((stat, headers) => { 27 headers[HTTP2_HEADER_LAST_MODIFIED] = stat.mtime.toUTCString(); 28 }), 29 offset: 8, 30 length: 3 31 }); 32}); 33server.listen(0, () => { 34 35 const client = http2.connect(`http://localhost:${server.address().port}`); 36 const req = client.request(); 37 38 req.on('response', common.mustCall((headers) => { 39 assert.strictEqual(headers[HTTP2_HEADER_CONTENT_TYPE], 'text/plain'); 40 assert.strictEqual(+headers[HTTP2_HEADER_CONTENT_LENGTH], 3); 41 assert.strictEqual(headers[HTTP2_HEADER_LAST_MODIFIED], 42 stat.mtime.toUTCString()); 43 })); 44 req.setEncoding('utf8'); 45 let check = ''; 46 req.on('data', (chunk) => check += chunk); 47 req.on('end', common.mustCall(() => { 48 assert.strictEqual(check, data.toString('utf8', 8, 11)); 49 client.close(); 50 server.close(); 51 })); 52 req.end(); 53}); 54