Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-http-server-request-timeout-upgrade.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dd7269621e2d47792531aaa2954c713a3b6641a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';

const common = require('../common');
const assert = require('assert');
const { createServer } = require('http');
const { connect } = require('net');

// This test validates that the requestTimeoout
// is disabled after the connection is upgraded.

const server = createServer(common.mustNotCall());

// 0 seconds is the default
assert.strictEqual(server.requestTimeout, 0);
const requestTimeout = common.platformTimeout(1000);
server.requestTimeout = requestTimeout;
assert.strictEqual(server.requestTimeout, requestTimeout);

server.on('upgrade', common.mustCall((req, socket, head) => {
  socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n');
  socket.write('Upgrade: WebSocket\r\n');
  socket.write('Connection: Upgrade\r\n\r\n');
  socket.pipe(socket);
}));

server.listen(0, common.mustCall(() => {
  const client = connect(server.address().port);
  let response = '';

  client.on('data', common.mustCallAtLeast((chunk) => {
    response += chunk.toString('utf-8');
  }, 1));

  client.on('end', common.mustCall(() => {
    assert.strictEqual(
      response,
      'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
      'Upgrade: WebSocket\r\n' +
      'Connection: Upgrade\r\n\r\n' +
      '12345678901234567890'
    );

    server.close();
  }));

  client.resume();
  client.write('GET / HTTP/1.1\r\n');
  client.write('Upgrade: WebSocket\r\n');
  client.write('Connection: Upgrade\r\n\r\n');

  setTimeout(() => {
    client.write('12345678901234567890');
    client.end();
  }, common.platformTimeout(2000)).unref();
}));