2017-07-17 10:29:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-08-07 07:54:44 +02:00
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2017-10-06 10:34:26 -07:00
|
|
|
const fixtures = require('../common/fixtures');
|
2019-12-25 18:02:16 +01:00
|
|
|
const assert = require('assert');
|
2017-07-17 10:29:42 -07:00
|
|
|
const http2 = require('http2');
|
|
|
|
|
|
|
|
const {
|
|
|
|
HTTP2_HEADER_CONTENT_TYPE,
|
|
|
|
HTTP2_HEADER_STATUS
|
|
|
|
} = http2.constants;
|
|
|
|
|
2017-10-06 10:34:26 -07:00
|
|
|
const fname = fixtures.path('elipses.txt');
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
const server = http2.createServer();
|
|
|
|
server.on('stream', (stream) => {
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.respondWithFile(fname, {
|
|
|
|
[HTTP2_HEADER_STATUS]: 204,
|
|
|
|
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
|
|
|
|
});
|
2017-12-08 16:41:38 -05:00
|
|
|
}, {
|
2017-07-17 10:29:42 -07:00
|
|
|
code: 'ERR_HTTP2_PAYLOAD_FORBIDDEN',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'Error',
|
2017-07-17 10:29:42 -07:00
|
|
|
message: 'Responses with 204 status must not have a payload'
|
2017-12-08 16:41:38 -05:00
|
|
|
});
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.respond({});
|
|
|
|
stream.end();
|
|
|
|
});
|
|
|
|
server.listen(0, () => {
|
|
|
|
const client = http2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
const req = client.request();
|
|
|
|
req.on('response', common.mustCall());
|
|
|
|
req.on('data', common.mustNotCall());
|
|
|
|
req.on('end', common.mustCall(() => {
|
2017-12-12 11:34:17 -08:00
|
|
|
client.close();
|
2017-07-17 10:29:42 -07:00
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
req.end();
|
|
|
|
});
|