11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst http = require('http'); 51cb0ef41Sopenharmony_ciconst net = require('net'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst response = Buffer.from('HTTP/1.1 200 OK\r\n' + 81cb0ef41Sopenharmony_ci 'Content-Length: 6\r\n' + 91cb0ef41Sopenharmony_ci 'Transfer-Encoding: Chunked\r\n' + 101cb0ef41Sopenharmony_ci '\r\n' + 111cb0ef41Sopenharmony_ci '6\r\nfoobar' + 121cb0ef41Sopenharmony_ci '0\r\n'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst server = net.createServer(common.mustCall((conn) => { 151cb0ef41Sopenharmony_ci conn.write(response); 161cb0ef41Sopenharmony_ci})); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 191cb0ef41Sopenharmony_ci const req = http.get(`http://localhost:${server.address().port}/`); 201cb0ef41Sopenharmony_ci req.end(); 211cb0ef41Sopenharmony_ci req.on('error', common.mustCall((err) => { 221cb0ef41Sopenharmony_ci const reason = 'Content-Length can\'t be present with Transfer-Encoding'; 231cb0ef41Sopenharmony_ci assert.strictEqual(err.message, `Parse Error: ${reason}`); 241cb0ef41Sopenharmony_ci assert(err.bytesParsed < response.length); 251cb0ef41Sopenharmony_ci assert(err.bytesParsed >= response.indexOf('Transfer-Encoding')); 261cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); 271cb0ef41Sopenharmony_ci assert.strictEqual(err.reason, reason); 281cb0ef41Sopenharmony_ci assert.deepStrictEqual(err.rawPacket, response); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci server.close(); 311cb0ef41Sopenharmony_ci })); 321cb0ef41Sopenharmony_ci})); 33