11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// This test ensures that a Trailer header is set only when a chunked transfer 51cb0ef41Sopenharmony_ci// encoding is used. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst http = require('http'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall(function(req, res) { 111cb0ef41Sopenharmony_ci res.setHeader('Trailer', 'baz'); 121cb0ef41Sopenharmony_ci const trailerInvalidErr = { 131cb0ef41Sopenharmony_ci code: 'ERR_HTTP_TRAILER_INVALID', 141cb0ef41Sopenharmony_ci message: 'Trailers are invalid with this transfer encoding', 151cb0ef41Sopenharmony_ci name: 'Error' 161cb0ef41Sopenharmony_ci }; 171cb0ef41Sopenharmony_ci assert.throws(() => res.writeHead(200, { 'Content-Length': '2' }), 181cb0ef41Sopenharmony_ci trailerInvalidErr); 191cb0ef41Sopenharmony_ci res.removeHeader('Trailer'); 201cb0ef41Sopenharmony_ci res.end('ok'); 211cb0ef41Sopenharmony_ci})); 221cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 231cb0ef41Sopenharmony_ci http.get({ port: server.address().port }, common.mustCall((res) => { 241cb0ef41Sopenharmony_ci assert.strictEqual(res.statusCode, 200); 251cb0ef41Sopenharmony_ci let buf = ''; 261cb0ef41Sopenharmony_ci res.on('data', (chunk) => { 271cb0ef41Sopenharmony_ci buf += chunk; 281cb0ef41Sopenharmony_ci }).on('end', common.mustCall(() => { 291cb0ef41Sopenharmony_ci assert.strictEqual(buf, 'ok'); 301cb0ef41Sopenharmony_ci })); 311cb0ef41Sopenharmony_ci server.close(); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci})); 34