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'); 9 10const { 11 HTTP2_HEADER_CONTENT_TYPE, 12 HTTP2_HEADER_STATUS 13} = http2.constants; 14 15const fname = fixtures.path('elipses.txt'); 16 17const server = http2.createServer(); 18server.on('stream', (stream) => { 19 stream.respondWithFile(fname, { 20 [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain' 21 }, { 22 statCheck(stat, headers) { 23 // Abort the send and return a 304 Not Modified instead 24 stream.respond({ [HTTP2_HEADER_STATUS]: 304 }); 25 return false; 26 } 27 }); 28}); 29server.listen(0, () => { 30 31 const client = http2.connect(`http://localhost:${server.address().port}`); 32 const req = client.request(); 33 34 req.on('response', common.mustCall((headers) => { 35 assert.strictEqual(headers[HTTP2_HEADER_STATUS], 304); 36 assert.strictEqual(headers[HTTP2_HEADER_CONTENT_TYPE], undefined); 37 })); 38 39 req.on('data', common.mustNotCall()); 40 req.on('end', common.mustCall(() => { 41 client.close(); 42 server.close(); 43 })); 44 req.end(); 45}); 46