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

test-http-keep-alive-close-on-header.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b36fb2e8db9a5aecb66c45ba936b8441e01f32c8 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
require('../common');
const assert = require('assert');
const http = require('http');

const body = 'hello world\n';
const headers = {'connection': 'keep-alive'};

const server = http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'});
  res.write(body);
  res.end();
});

let connectCount = 0;


server.listen(0, function() {
  const agent = new http.Agent({ maxSockets: 1 });
  const name = agent.getName({ port: this.address().port });
  let request = http.request({
    method: 'GET',
    path: '/',
    headers: headers,
    port: this.address().port,
    agent: agent
  }, function(res) {
    assert.strictEqual(1, agent.sockets[name].length);
    res.resume();
  });
  request.on('socket', function(s) {
    s.on('connect', function() {
      connectCount++;
    });
  });
  request.end();

  request = http.request({
    method: 'GET',
    path: '/',
    headers: headers,
    port: this.address().port,
    agent: agent
  }, function(res) {
    assert.strictEqual(1, agent.sockets[name].length);
    res.resume();
  });
  request.on('socket', function(s) {
    s.on('connect', function() {
      connectCount++;
    });
  });
  request.end();
  request = http.request({
    method: 'GET',
    path: '/',
    headers: headers,
    port: this.address().port,
    agent: agent
  }, function(response) {
    response.on('end', function() {
      assert.strictEqual(1, agent.sockets[name].length);
      server.close();
    });
    response.resume();
  });
  request.on('socket', function(s) {
    s.on('connect', function() {
      connectCount++;
    });
  });
  request.end();
});

process.on('exit', function() {
  assert.strictEqual(3, connectCount);
});