11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst { mustCall } = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { createServer } = require('http');
51cb0ef41Sopenharmony_ciconst { createConnection } = require('net');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst server = createServer();
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciserver.on('request', mustCall((req, res) => {
101cb0ef41Sopenharmony_ci  res.write('asd', () => {
111cb0ef41Sopenharmony_ci    res.socket.emit('error', new Error('kaboom'));
121cb0ef41Sopenharmony_ci  });
131cb0ef41Sopenharmony_ci}));
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciserver.listen(0, mustCall(() => {
161cb0ef41Sopenharmony_ci  const c = createConnection(server.address().port);
171cb0ef41Sopenharmony_ci  let received = '';
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  c.on('connect', mustCall(() => {
201cb0ef41Sopenharmony_ci    c.write('GET /blah HTTP/1.1\r\n\r\n');
211cb0ef41Sopenharmony_ci  }));
221cb0ef41Sopenharmony_ci  c.on('data', mustCall((data) => {
231cb0ef41Sopenharmony_ci    received += data.toString();
241cb0ef41Sopenharmony_ci  }));
251cb0ef41Sopenharmony_ci  c.on('end', mustCall(() => {
261cb0ef41Sopenharmony_ci    // Should not include anything else after asd.
271cb0ef41Sopenharmony_ci    assert.strictEqual(received.indexOf('asd\r\n'), received.length - 5);
281cb0ef41Sopenharmony_ci    c.end();
291cb0ef41Sopenharmony_ci  }));
301cb0ef41Sopenharmony_ci  c.on('close', mustCall(() => server.close()));
311cb0ef41Sopenharmony_ci}));
32