1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const fixtures = require('../common/fixtures'); 7const assert = require('assert'); 8const http2 = require('http2'); 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 assert.throws(() => { 20 stream.respondWithFile(fname, { 21 [HTTP2_HEADER_STATUS]: 204, 22 [HTTP2_HEADER_CONTENT_TYPE]: 'text/plain' 23 }); 24 }, { 25 code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN', 26 name: 'Error', 27 message: 'Responses with 204 status must not have a payload' 28 }); 29 stream.respond({}); 30 stream.end(); 31}); 32server.listen(0, () => { 33 const client = http2.connect(`http://localhost:${server.address().port}`); 34 const req = client.request(); 35 req.on('response', common.mustCall()); 36 req.on('data', common.mustNotCall()); 37 req.on('end', common.mustCall(() => { 38 client.close(); 39 server.close(); 40 })); 41 req.end(); 42}); 43