11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst http = require('http');
71cb0ef41Sopenharmony_ciconst net = require('net');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst msg = [
101cb0ef41Sopenharmony_ci  'POST / HTTP/1.1',
111cb0ef41Sopenharmony_ci  'Host: 127.0.0.1',
121cb0ef41Sopenharmony_ci  'Transfer-Encoding: chunkedchunked',
131cb0ef41Sopenharmony_ci  '',
141cb0ef41Sopenharmony_ci  '1',
151cb0ef41Sopenharmony_ci  'A',
161cb0ef41Sopenharmony_ci  '0',
171cb0ef41Sopenharmony_ci  '',
181cb0ef41Sopenharmony_ci].join('\r\n');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => {
211cb0ef41Sopenharmony_ci  // Verify that no data is received
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  req.on('data', common.mustNotCall());
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  req.on('end', common.mustNotCall(() => {
261cb0ef41Sopenharmony_ci    res.writeHead(200, { 'Content-Type': 'text/plain' });
271cb0ef41Sopenharmony_ci    res.end();
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci}, 1));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciserver.listen(0, common.mustSucceed(() => {
321cb0ef41Sopenharmony_ci  const client = net.connect(server.address().port, 'localhost');
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  let response = '';
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  client.on('data', common.mustCall((chunk) => {
371cb0ef41Sopenharmony_ci    response += chunk;
381cb0ef41Sopenharmony_ci  }));
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  client.setEncoding('utf8');
411cb0ef41Sopenharmony_ci  client.on('error', common.mustNotCall());
421cb0ef41Sopenharmony_ci  client.on('end', common.mustCall(() => {
431cb0ef41Sopenharmony_ci    assert.strictEqual(
441cb0ef41Sopenharmony_ci      response,
451cb0ef41Sopenharmony_ci      'HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n'
461cb0ef41Sopenharmony_ci    );
471cb0ef41Sopenharmony_ci    server.close();
481cb0ef41Sopenharmony_ci  }));
491cb0ef41Sopenharmony_ci  client.write(msg);
501cb0ef41Sopenharmony_ci  client.resume();
511cb0ef41Sopenharmony_ci}));
52