11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst { createServer } = require('http');
61cb0ef41Sopenharmony_ciconst { connect } = require('net');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// This test validates that the requestTimeoout
91cb0ef41Sopenharmony_ci// is disabled after the connection is upgraded.
101cb0ef41Sopenharmony_cilet sendDelayedRequestHeaders;
111cb0ef41Sopenharmony_ciconst requestTimeout = common.platformTimeout(2000);
121cb0ef41Sopenharmony_ciconst server = createServer({
131cb0ef41Sopenharmony_ci  headersTimeout: 0,
141cb0ef41Sopenharmony_ci  requestTimeout,
151cb0ef41Sopenharmony_ci  keepAliveTimeout: 0,
161cb0ef41Sopenharmony_ci  connectionsCheckingInterval: requestTimeout / 4
171cb0ef41Sopenharmony_ci}, common.mustNotCall());
181cb0ef41Sopenharmony_ciserver.on('connection', common.mustCall(() => {
191cb0ef41Sopenharmony_ci  assert.strictEqual(typeof sendDelayedRequestHeaders, 'function');
201cb0ef41Sopenharmony_ci  sendDelayedRequestHeaders();
211cb0ef41Sopenharmony_ci}));
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciassert.strictEqual(server.requestTimeout, requestTimeout);
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciserver.on('upgrade', common.mustCall((req, socket, head) => {
261cb0ef41Sopenharmony_ci  socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n');
271cb0ef41Sopenharmony_ci  socket.write('Upgrade: WebSocket\r\n');
281cb0ef41Sopenharmony_ci  socket.write('Connection: Upgrade\r\n\r\n');
291cb0ef41Sopenharmony_ci  socket.pipe(socket);
301cb0ef41Sopenharmony_ci}));
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
331cb0ef41Sopenharmony_ci  const client = connect(server.address().port);
341cb0ef41Sopenharmony_ci  let response = '';
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  client.setEncoding('utf8');
371cb0ef41Sopenharmony_ci  client.on('data', common.mustCallAtLeast((chunk) => {
381cb0ef41Sopenharmony_ci    response += chunk;
391cb0ef41Sopenharmony_ci  }, 1));
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  client.on('end', common.mustCall(() => {
421cb0ef41Sopenharmony_ci    assert.strictEqual(
431cb0ef41Sopenharmony_ci      response,
441cb0ef41Sopenharmony_ci      'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
451cb0ef41Sopenharmony_ci      'Upgrade: WebSocket\r\n' +
461cb0ef41Sopenharmony_ci      'Connection: Upgrade\r\n\r\n' +
471cb0ef41Sopenharmony_ci      '12345678901234567890'
481cb0ef41Sopenharmony_ci    );
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci    server.close();
511cb0ef41Sopenharmony_ci  }));
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  client.resume();
541cb0ef41Sopenharmony_ci  client.write('GET / HTTP/1.1\r\n');
551cb0ef41Sopenharmony_ci  client.write('Upgrade: WebSocket\r\n');
561cb0ef41Sopenharmony_ci  client.write('Connection: Upgrade\r\n\r\n');
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci  sendDelayedRequestHeaders = common.mustCall(() => {
591cb0ef41Sopenharmony_ci    setTimeout(() => {
601cb0ef41Sopenharmony_ci      client.write('12345678901234567890');
611cb0ef41Sopenharmony_ci      client.end();
621cb0ef41Sopenharmony_ci    }, requestTimeout * 2).unref();
631cb0ef41Sopenharmony_ci  });
641cb0ef41Sopenharmony_ci}));
65