11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Verify that a request with a space before the content length will result
91cb0ef41Sopenharmony_ci// in a 400 Bad Request.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustNotCall());
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(start));
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction start() {
161cb0ef41Sopenharmony_ci  const sock = net.connect(server.address().port);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  sock.write('GET / HTTP/1.1\r\nHost: localhost:5000\r\n' +
191cb0ef41Sopenharmony_ci    'Content-Length : 5\r\n\r\nhello');
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  let body = '';
221cb0ef41Sopenharmony_ci  sock.setEncoding('utf8');
231cb0ef41Sopenharmony_ci  sock.on('data', (chunk) => {
241cb0ef41Sopenharmony_ci    body += chunk;
251cb0ef41Sopenharmony_ci  });
261cb0ef41Sopenharmony_ci  sock.on('end', common.mustCall(function() {
271cb0ef41Sopenharmony_ci    assert.strictEqual(body, 'HTTP/1.1 400 Bad Request\r\n' +
281cb0ef41Sopenharmony_ci      'Connection: close\r\n\r\n');
291cb0ef41Sopenharmony_ci    server.close();
301cb0ef41Sopenharmony_ci  }));
311cb0ef41Sopenharmony_ci}
32