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_ci['on', 'addListener', 'prependListener'].forEach((testFn) => {
81cb0ef41Sopenharmony_ci  let received = '';
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci  const server = http.createServer(function(req, res) {
111cb0ef41Sopenharmony_ci    res.writeHead(200);
121cb0ef41Sopenharmony_ci    res.end();
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci    req.socket[testFn]('data', function(data) {
151cb0ef41Sopenharmony_ci      received += data;
161cb0ef41Sopenharmony_ci    });
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci    server.close();
191cb0ef41Sopenharmony_ci  }).listen(0, function() {
201cb0ef41Sopenharmony_ci    const socket = net.connect(this.address().port, function() {
211cb0ef41Sopenharmony_ci      socket.write('PUT / HTTP/1.1\r\n\r\n');
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci      socket.once('data', function() {
241cb0ef41Sopenharmony_ci        socket.end('hello world');
251cb0ef41Sopenharmony_ci      });
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci      socket.on('end', common.mustCall(() => {
281cb0ef41Sopenharmony_ci        assert.strictEqual(received, 'hello world',
291cb0ef41Sopenharmony_ci                           `failed for socket.${testFn}`);
301cb0ef41Sopenharmony_ci      }));
311cb0ef41Sopenharmony_ci    });
321cb0ef41Sopenharmony_ci  });
331cb0ef41Sopenharmony_ci});
34